This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes jsp, servlet-mapping, forward request problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp, servlet-mapping, forward request problem" Watch "jsp, servlet-mapping, forward request problem" New topic
Author

jsp, servlet-mapping, forward request problem

dana eckart
Greenhorn

Joined: Feb 21, 2001
Posts: 2
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

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!


Customer surveys are for companies who didn't pay proper attention to begin with.
dana eckart
Greenhorn

Joined: Feb 21, 2001
Posts: 2
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>
 
 
subject: jsp, servlet-mapping, forward request problem
 
Similar Threads
URLs and RequestDispatcher.forward()
problem with FORM based authentication
help with module level struts config
Servlet Context Path Issue
Resin 3 Forms Authentication