April 3rd, 2003, 11:50 AM
Getting a http 404 error when redirecting from servlets
Hi Ive got a problem with calling servlets on tomcat.
The directory on the hosts account as follows
jsps are put in the
servlets are to be put under
I have set up my servlets in the following directories
I am using a jsp to login, and the form action is as follows
I know it Its definetly hitting the servlet as if I change the variable to HSMETHOD=1, then I get an exception which is correct. Because the code is looking for the variable HsMethod as it uses it in a switch statement
My problem is when I try to submit from my login page I get an http 404 not found error.
I think the servlet may not be able to find the way back up to the folder where the jsp is held.
I have tried using the following code to get back to the folder and tried putting the jsp in different folders but I only ever get the http 404 not found error
RequestDispatcher dispatcher = context.getRequestDispatcher(target);
but it doesnt seem to make a difference
the servlet can also be called with
any help appreciated
April 6th, 2003, 03:15 PM
can you post all your servlet code and the jsp?
April 6th, 2003, 06:40 PM
Heres the code
Hi, Thanks for the reply!
The basic way I have coded it to work is to hit a switch statement to check a valid login name e and password, if invalid it redirects to the login page otherwise redirects to the memebers area.
Could it be that there may be an area further down the chain?
Im not sure but I think this would give a tomcat error screen and not the 404?
Heres the code, if you anuthing else I can sendit to your email if thats ok?
Ive attached the java file as I was too long to submit
<link rel="stylesheet" href="DrumpellierStyleSheet.css" type="text/css">
<font face="Book Antiqua" color="#000066"><u><h2>Members Login </h2></u></font>
<form name="frmLoginForm" method="post" action="com.golfclub.Controller?HsMethod=1">
<table cellspacing=0 cellpadding=2 width="200" bgcolor=#191970 border=0>
<table cellspacing="0" cellpadding="2" width="100%" bgcolor="#eeeeee" border="0">
<td align="middle" bgcolor="#ffffff">
<table cellspacing="6" cellpadding="6" width="100%" bgcolor="#ffffff" border="0">
<div align="center"><span class="textLrg">Enter your Member
Name and Password to Log on.  </span> </div>
<table cellspacing="0" cellpadding="4" border="0">
<table cellspacing="0" cellpadding="2" border="0">
<td noWrap align="right" class="textLrg" width="120">Member
<input type="text" name="MemberName" size="30" maxlength="30">
<td noWrap align=right class="textLrg" width="120">Password:</td>
<input type="password" name="Password" size="30" maxlength="30">
<td noWrap align=middle colspan=2>
<input type=checkbox value=y name=.persistent>
<span class="textLrg">Remember my Member Name on this computer</span></td>
<td width="120"> </td>
<input type="submit" name="btnLogin" value="Login">
<td valign=top align=middle>
<div align="center"><a href="LoginHelp.html"><span class="textLrgLink"><img src="images/BulletPoint.gif" border="0"> Log-in
Help</span></a> <a href=""><span class="textLrgLink"><img src="images/BulletPoint.gif" border="0"></span></a>
<a href="LoginHelp.html" class="textLrgLink">Forgot your
<table border="0" cellpadding="0" cellspacing="0" width="680">
String sErrorMessage = (String)request.getAttribute("sErrorMessage");
<td width="10" height="10" colspan="1"></td>
<td width="670" colspan="3"><%= request.getAttribute("sErrorMessage") %></td>
<p><img src="images/Advert1.gif" width="468" height="60">
April 7th, 2003, 01:24 PM
Hmm, just looking at this briefly, it does not look like the action is set to the right url.
An action of
will get turned into
by the web browser. Notice the 'jserv' app server name is not there.
April 8th, 2003, 05:44 AM
Yeah, your right,I had missed out the jserv,Sorry its a bit of code I had modified when trying to get it to work onmy own system.
I tried caliing it with the
I think it may be to do with the redirection fromthe servlet.
I had just got a copy of tomcat 4 and tried it on that, and got a file not found error but the url was looking in the folder above the folder the file is in.
Unfortunatley my machine then crashed and wont boot up because the registry is messed, So Im working on fixing that just now
April 8th, 2003, 08:39 AM
I cannot see anything wrong with your code just looking at it. I cannot put it in my IDE as I don't have all the classes that you are importing, so it will not compile for me regardless. As far as I can tell you appear to be using the redirect as intended.
A couple of things though. Make sure that the file name is exactly as you have it in your servlet. I believe that requests to Tomcat are case specific by default. "MembersRedirect" is not the same as "membersRedirect" and so on.
Also, if you are doing the exact same thing in both the doPost and doGet, I would strongly suggest making a doRequest mehod and have both the doPost and doGet call it so that you are not repeating code. I have found that having two methods do the same turns into a maintanance nightmare.
April 8th, 2003, 03:04 PM
Thanks for looking over the code!
Good idea about the do request,Ill make that changes. Only problem is my pc has just crashedm registry totally gone so. ill need to set it up again.SO it will be a day before I get thinks back up and running.
If you want to try and compile all the code, I could zip it up, and attach it to a post or email it to you?
Think Im pretty close to getting it working, just needs a few tweaks! Ill try the suggestions you have made.
Thanks for all your help so far!