Servlet magically invoked twice
Hey all
I have this servlet which picks up all requests against a certain URI (/users/*) - parses the URI and then redirects to a JSP along with a certain parameter. When debugging the servlet I've found that it is invoked twice, the first time is fully valid and it parses the username and redirects to the JSP with a correct parameter. The second (and unnecessary) time it is invoked it doesn't parse the URI but the filename of the CSS file which the JSP page uses. So the URI the second time is something like "web-app/include/style.css". Any ideas why this is happening?
protectedvoid doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
String uri = req.getRequestURI();
String username =new String();
int slash = uri.lastIndexOf(("user/"));
if(slash != -1){
username = uri.substring(slash + 5);
//If username exists
if(appManager.getPersonByUsername(username) !=null){
dispatcher = getServletContext().
getRequestDispatcher("/publicFiles.jsp?username=" + username);
dispatcher.forward(req, res);
return;
}
}else
dispatcher = getServletContext().
getRequestDispatcher("/index.jsp");
dispatcher.forward(req, res);
}
Thanks!

