Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet mapping wild card problem

843842Mar 2 2010 — edited Mar 3 2010
I'm trying to set up a servlet that can be accessed from a wild card mapping. Please see my code snippets below.

It displays correctly if I hit: http://localhost:8080/servletBase/doc?id=56
The jsp displays the properly coded error with: http://localhost:8080/servletBase/doc
Many, many doGet exceptions, to the point of stack overflow with :http://localhost:8080/servletBase/doc/
Same as above, but this is my desired url structure (where 'item' can be anything): http://localhost:8080/servletBase/doc/item?id=65

web.xml
<servlet>
  		<servlet-name>Servlet One</servlet-name>
		<servlet-class>com.web.servlet.Servlet</servlet-class>
  </servlet>
  
  <servlet-mapping>
  		<servlet-name>Servlet One</servlet-name>
		<url-pattern>/doc/*</url-pattern>
  </servlet-mapping>
servlet code
public void doGet(HttpServletRequest request,
					HttpServletResponse response)
					throws IOException, ServletException {

		String id = request.getParameter("id");

		request.setAttribute("queryResult", id);
		RequestDispatcher view = request.getRequestDispatcher("result.jsp");
		view.forward(request, response);

	}
jsp code
<%
	out.println("The id passed was: " + request.getAttribute("queryResult"));
%>
ERROR
javax.servlet.ServletException: Servlet execution threw an exception
	com.web.servlet.Servlet.doGet(Servlet.java:24)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.web.servlet.Servlet.doGet(Servlet.java:24)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.web.servlet.Servlet.doGet(Servlet.java:24)
...
...
...
java.lang.StackOverflowError
	org.apache.catalina.connector.Request.setAttribute(Request.java:1414)
	org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
	com.web.servlet.Servlet.doGet(Servlet.java:22)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.web.servlet.Servlet.doGet(Servlet.java:24)
...
...
...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2010
Added on Mar 2 2010
2 comments
785 views