Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 3rd, 2003, 11:50 AM
craigangus craigangus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 craigangus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

www.drumpellier.com/public_html/jserv/

folder

servlets are to be put under

http://www.drumpellier.com/public_h...EB-INF/classes/

folder

I have set up my servlets in the following directories

http://www.drumpellier.com/public_h...es/com/golfclub

folder

I am using a jsp to login, and the form action is as follows

action="com.golfclub.Controller?HsMethod=1"

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

String target="/MembersRedirect.jsp";
RequestDispatcher dispatcher = context.getRequestDispatcher(target);
dispatcher.forward(request, response);

and also

response.sendRedirect(response.encodeRedirectURL("../MembersLogout.jsp"));

but it doesnt seem to make a difference

the servlet can also be called with

http://www.drumpellier.com/jserv/co...ller?HsMethod=1

any help appreciated

Reply With Quote
  #2  
Old April 6th, 2003, 03:15 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
can you post all your servlet code and the jsp?

Reply With Quote
  #3  
Old April 6th, 2003, 06:40 PM
craigangus craigangus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 craigangus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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


MembersLogin.jsp


<html>
<head>
<title>Members Login</title>

<link rel="stylesheet" href="DrumpellierStyleSheet.css" type="text/css">
<script>
function focusFirstElement(){
frmLoginForm.MemberName.focus();
}
</script>
</head>

<body background="images/background.gif" bgcolor="#ffffff" text="#000000" topmargin="0" bottommargin="0" onLoad="javascript:focusFirstElement()">
<div align="center">
<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>
<tr>
<td>
<table cellspacing="0" cellpadding="2" width="100%" bgcolor="#eeeeee" border="0">
<tr>
<td align="middle" bgcolor="#ffffff">
<table cellspacing="6" cellpadding="6" width="100%" bgcolor="#ffffff" border="0">
<tr bgcolor="#eeeeee">
<td align=middle>
<div align="center"><span class="textLrg">Enter your Member
Name and Password to Log on.&nbsp </span> </div>
<table cellspacing="0" cellpadding="4" border="0">
<tr>
<td align=right>
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td noWrap align="right" class="textLrg" width="120">Member
Name:</td>
<td width="170">
<input type="text" name="MemberName" size="30" maxlength="30">
</td>
</tr>
<tr>
<td noWrap align=right class="textLrg" width="120">Password:</td>
<td width="170">
<input type="password" name="Password" size="30" maxlength="30">
</td>
</tr>
<tr>
<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>
</tr>
<tr>
<td width="120">&nbsp;</td>
<td width="170">
<input type="submit" name="btnLogin" value="Login">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor=#eeeeee>
<td valign=top align=middle>
<div align="center"><a href="LoginHelp.html"><span class="textLrgLink"><img src="images/BulletPoint.gif" border="0">&nbsp;Log-in
Help</span></a>&nbsp;&nbsp;<a href=""><span class="textLrgLink"><img src="images/BulletPoint.gif" border="0"></span></a>
<a href="LoginHelp.html" class="textLrgLink">Forgot your
Password?</a> </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="680">
<%
String sErrorMessage = (String)request.getAttribute("sErrorMessage");
if(sErrorMessage!=null) {
%>
<tr>
<td width="10" height="10" colspan="1"></td>
<td width="670" colspan="3"><%= request.getAttribute("sErrorMessage") %></td>
</tr>
<%
//request.removeValue("sErrorMessage");
}
%>
</table>
<p><img src="images/Advert1.gif" width="468" height="60">
</p>
</form>
<p>&nbsp;</p>
</div>
</body>
</html>
Attached Files
File Type: java controller.java (11.5 KB, 221 views)

Reply With Quote
  #4  
Old April 7th, 2003, 01:24 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
Hmm, just looking at this briefly, it does not look like the action is set to the right url.

An action of
Code:
com.golfclub.Controller?HsMethod=1

will get turned into

by the web browser. Notice the 'jserv' app server name is not there.

Reply With Quote
  #5  
Old April 8th, 2003, 05:44 AM
craigangus craigangus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 craigangus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Your right

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

Thanks

Craig

Reply With Quote
  #6  
Old April 8th, 2003, 08:39 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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.

Reply With Quote
  #7  
Old April 8th, 2003, 03:04 PM
craigangus craigangus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 craigangus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

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!

Craig

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Getting a http 404 error when redirecting from servlets


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT