[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Filter problem

Hello,

I have a java web application, I want 2 filters in it:

- LogFilter: mapped to /*
- RestrictedFilter: mapped to /WEB-INF/ticketing/*

Only the first one is executed. Have included system.out.print in each filter, so I know only the first filter is executed.

Attached is web.xml

Does anyone have an idea how to fix this?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ticketing</display-name>
  <resource-ref>
    <description>MySQL DataSource</description>
    <res-ref-name>jdbc/ticketing</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ProcessTicket</display-name>
    <servlet-name>ProcessTicket</servlet-name>
    <servlet-class>servlets.ProcessTicket</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ProcessTicket</servlet-name>
    <url-pattern>/ProcessTicketServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>CreateUserServlet</display-name>
    <servlet-name>CreateUserServlet</servlet-name>
    <servlet-class>servlets.CreateUserServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CreateUserServlet</servlet-name>
    <url-pattern>/CreateUserServlet</url-pattern>
  </servlet-mapping>
  <listener>
    <listener-class>listeners.MyListener</listener-class>
  </listener>
  <servlet>
    <description></description>
    <display-name>LoginServlet</display-name>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>servlets.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
  <filter>
    <display-name>LogFilter</display-name>
    <filter-name>LogFilter</filter-name>
    <filter-class>filters.LogFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>LogFilter</filter-name>
    <url-pattern>/LogFilter</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>LogFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <display-name>RestrictedFilter</display-name>
    <filter-name>RestrictedFilter</filter-name>
    <filter-class>filters.RestrictedFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>RestrictedFilter</filter-name>
    <url-pattern>/RestrictedFilter</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>RestrictedFilter</filter-name>
    <url-pattern>/WEB-INF/ticketing/*</url-pattern>
  </filter-mapping>
</web-app>

Open in new window

0
wolfje_xp
Asked:
wolfje_xp
  • 3
  • 3
1 Solution
 
objectsCommented:
>     /WEB-INF/ticketing/*

you can't add a filter to WEB-INF as its not publicly accessible
ie. you cannot request it so no pojnt adding a filter
0
 
wolfje_xpAuthor Commented:
Ok, I understand that.
But I use a master page, when a user is logged in, the pages included in the master page are in /WEB-INF/ticketing/...
I want to prevent someone typing in his browser master.jsp?page=loggedin or something, unless there's a user on the context ...
How can I do that ?  Should I move the include pages out of WEB-INF ?
0
 
objectsCommented:
you would need to filter on /master.jsp
or check in your master that the include can be accessed

filters work on the request path, not the file path in your application
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
wolfje_xpAuthor Commented:
It works half: when a user logs in correct, he is forwarded from master.jsp to ticketing.jsp (same idea as master page), filter is on /ticketing.jsp.
When I access ticketing.jsp from brower without being logged in (via master.jsp), filter is invoked, but instead of forwarding me to forbidden.html I get an error: org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
Any idea?
0
 
objectsCommented:
hard to say without seeing your code
0
 
wolfje_xpAuthor Commented:
Seems I cannot upload the code ...
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now