This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

jsp, servlet-mapping, forward request problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 28402
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
dana eckart
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>
 
Men call me Jim. Women look past me to this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic