Problems with filters and jsp pages.
I have the following simple filter that checks if there is user information in the session object and redirects accordingly:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
publicclass LoginFilterimplements Filter
{
publicvoid init(FilterConfig filterConfig){}
publicvoid destroy(){}
publicvoid doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
System.out.println("filter");
HttpSession session = ((HttpServletRequest)request).getSession();
String action = request.getParameter("action");
if(action !=null && !action.equals("login") && !action.equals("wronglogin"))
{
if(session.getAttribute("username") ==null)
{
((HttpServletResponse)response).sendRedirect("index.jsp?action=wronglogin");
System.out.println("User not OK, kicking out...");
}
else
{
chain.doFilter(request, response);
System.out.println("User OK, letting in...");
}
}
else
chain.doFilter(request, response);
}
}
The filter is mapped to an admin page with the name index.jsp. However, I get an error for every <% and %> tag in the file (there are quite a few) when I use the filter with the page. The page works fine without the filter, and the filter seems to work with pages without scriptlets (without the <% and %> tags). Here is the beginning of the error report:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /admin/index.jsp
Generated servlet error:
Syntax error on tokens, AnnotationName expected instead
An error occurred at line: 6 in the jsp file: /admin/index.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
An error occurred at line: 6 in the jsp file: /admin/index.jsp
Generated servlet error:
Syntax error on token ";", [ expected
An error occurred at line: 6 in the jsp file: /admin/index.jsp
Generated servlet error:
Syntax error on token ";", [ expected
An error occurred at line: 6 in the jsp file: /admin/index.jsp
Generated servlet error:
Syntax error on token ";", [ expected
...
Jasper gives me many errors per <% and %> tag. As you can see there is a <% tag on line 6. Any idea, why this does not work?
Thanks!
Message was edited by:
chincillya

