Servlet - RequestDispatch causes indefinite recursive - help

hi All,

I'm new to jsp/servlet technologies. I have this requirement not quite sure about how to do it and I have given it a futile try.

Requirement : These is a servlet called MainServlet. All the requests to my web app should pass through MainServlet.

So my MainServlet first looks for a login user id in the request parameter. If request parameter is null (means user haven't logged in yet), so I have to dispatch this to login.jsp page, (user name will be set in the request on successful login). If use have already logged in redirect to the welcome.jsp page.

My code snippet.

protectedvoid processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

if(request.getParameter(NetManConstants.USER_ID_PARAM)==null)

{

RequestDispatcher dispatcher = request.getRequestDispatcher(NetManConstants.LOGIN_PAGE);

dispatcher.forward(request,response);

}

else

{

out.println("Welcome back..");

}

out.close();

}

Netbeans generated process request shown above.

My web.xml entry :

<servlet>

<servlet-name>MainServlet</servlet-name>

<servlet-class>com.netman.servlets.mainServlet.MainServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>MainServlet</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>

So all my request goes to MainServlet, which dispatches it to login.jsp, but that request also come to MainServlet and it keeps recursively coming and ultimately crashing my web app..

How can I do this?

[2242 byte] By [chaos_begins_herea] at [2007-11-27 3:39:43]
# 1
2 possible solutions comes to mind:1) Put the login page outside the url-pattern of the servlet.2) Check in the servlet if the request URI does not equal to login page.
BalusCa at 2007-7-12 8:43:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...