Forward all requests to a servlet

Hi All,

I am new to web development and need some help from you guys.

My requirements are:

1. When a user types http://localhost:8080/someName, the request should be received by a servlet.

2. This servlet simply forwards the request to a jsp page "template.jsp"

I have the following codes and configuration of the web.xml

//*** Servlet named Dispatcher ************

/*

* Dispatcher.java

*

* Created on October 8, 2006, 8:27 PM

*/

package engine;

import java.io.*;

import java.util.Enumeration;

import javax.servlet.*;

import javax.servlet.http.*;

public class Dispatcher extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{

String path="/template.jsp";

RequestDispatcher rd;

rd = request.getRequestDispatcher(path);

rd.forward(request, response);

}

}

//*** The web.xml has the following entry *******

<servlet>

<servlet-name>Dispatcher</servlet-name>

<servlet-class>engine.Dispatcher</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Dispatcher</servlet-name>

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

</servlet-mapping>

My problem is that when I type http://localhost:8080/someName, it goes in an infinite loop.

Does anyone have a solution for this?

I would appreciate any solution to this problem.

Thank you all.

Sam

[1614 byte] By [embeddedbraina] at [2007-11-26 15:47:16]
# 1

Because you are directing all traffic i.e. /* in the url-pattern to the servlet an infinite loop is expected. try mapping the servlet to /dispatchServlet, that way you can safely redirect to /someName/template.jsp. To get the effect of having /someName/* routed to the Dispatcher, set up a welcome page of dispatchServlet.

Hope that help... Good luck.

j@Va_GuYa at 2007-7-8 22:06:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi j@Va_GuY ,Thank you very much for taking time to answer my question; I really appreciate it.
embeddedbraina at 2007-7-8 22:06:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...