#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep 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_ht...B-INF/classes/

    folder

    I have set up my servlets in the following directories

    http://www.drumpellier.com/public_ht...s/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/com...ler?HsMethod=1

    any help appreciated
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    can you post all your servlet code and the jsp?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep 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
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep 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
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep 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

IMN logo majestic logo threadwatch logo seochat tools logo