I'm using tomcat (3.2.3) on redhat linux (6.2). After reading Bergsten's "JavaServer Pages" book I wanted to try to build a small learning app with a login page (using the tech- niques described in chapter 14). I'm using a controller servlet that I map to "process", e.g., <servlet-mapping> <servlet-name>controller</servlet-name> <url-pattern>/process/*</url-pattern> </servlet-mapping> The servlet supports both a "login" and a "authuser" action. When I do http://localhost:8080/learn/process/login (where "learn" is the context) it brings up the "login.jsp" page like I expect. The "login.jsp" page uses the following for its form info: <form action="process/authuser" method="post"> ... However, when I submit the form, the browser gives me a 501 error saying that it can't find /learn/process/process/authuser If I start by doing http://localhost:8080/learn/login.jsp first, and submit without giving a username or password, the "authuser" action forwards me back to the "login.jsp" page after setting an "errorMsg" request attribute. E.g., request.setAttribute("errorMsg", "You must specify username/password."); request.getRequestDispatcher("/login.jsp") .forward(request, response); and this works fine, but when I then try to give a valid username/password I get the 501 error on location "/learn/process/process/authuser" again. It seems that because the forward leaves the URL as "http://localhost:8080/learn/process/authuser", that the action given by the form in login.jsp inserts an additonal process into the URL. I can't use a sendRedirect here since doing so removes the request scope attribute that I want to send. I've also tried forwarding using a relative path (i.e., "../login.jsp") but with no better results. ONE SOLUTION I've found is to use an absolute path for the form action (i.e., "/learn/process/authuser") and this works, but it defeats part of the reason for using the url-pattern since if I change the context (learn) I also have to change web pages. Am I understanding the problem correctly? Is this a problem with tomcat or my web server? Is there another work around, or is this the best that I can do? Thanks for any help.
You're missing the "servlet" element that specifies how the logical construct "servlet-name" is mapped to an actual servlet-class. Tomcat is actually providing you further abstraction, not less!
An IDE is no substitute for an Intelligent Developer.
Joined: Feb 21, 2001
Originally posted by Tim Holloway: You're missing the "servlet" element that specifies how the logical construct "servlet-name" is mapped to an actual servlet-class. Tomcat is actually providing you further abstraction, not less!
No, it's not missing I just didn't bother to mention it in my original post since it wouldn't have worked at all if I didn't have it. The part you ask about (in web.xml) is: <servlet> <servlet-name>controller</servlet-name> <servlet-class>com.cci.jsp.servlets.Controller</servlet-class> <load-on-startup>1</load-on-startup> </servlet>