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

[3775 byte] By [chincillyaa] at [2007-11-26 16:24:08]
# 1
What is the JSP scriptlet code at line 6 ? By looking at the code we can identify if there are any syntax errors, otherwise we can't really guess what might be the problem.
appy77a at 2007-7-8 22:48:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...