| |

VerySource

 Forgot password?
 Register
Search
View: 852|Reply: 5

Ask a filter question

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-4 12:00:01
| Show all posts |Read mode
I use a filter to filter if the user's login session is empty, if it is empty, it will automatically jump to the login page.

I put all the pages in the index directory and wrote it like this in the filter xml configuration
<url-pattern> / index / * </ url-pattern> Then I got the result I wanted.

But now I want one page home.jsp in the index directory not to be filtered by the filter, and other pages to be filtered by the filter. What should I write?
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-22 10:45:01
| Show all posts
You still put home.jsp outside the index directory!
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-3-23 14:30:02
| Show all posts
filter can be configured with parameters,
You can configure a parameter called exclusion, separated by commas, and the path recorded in it. Although it enters the filter, it is not processed.

such as
<filter>
.....
<init-param>
<param-name> exclusions </ param-name>
<param-value> /, /index.jsp, /login.do, /logout.do, /test.jsp </ param-value>
</ init-param>
</ filter>

filter

public class MyFilter implements Filter {
  Set exclusions;
  public void init (FilterConfig filterConfig) throws ServletException {
    super.init (filterConfig);
    String exclu = filterConfig.getInitParameter ("exclusions");
    exclusions = new HashSet ();
    // split operations
  }

    public void doFilter (ServletRequest request,
                       ServletResponse response,
                       FilterChain chain) throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    if (! exclusions.contains (httpRequest.getServletPath ())) {
      // original operation
    }
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-1 19:30:01
| Show all posts
If only one request is an exception, you can determine the request address in the filter
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-3 15:30:02
| Show all posts
The solution upstairs is upstairs.
However, it is best to separate filtered and unfiltered pages by directory.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-4 13:45:01
| Show all posts
Both the 2nd and 3rd floors can solve your problem
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list