Bookmark Topic Watch Topic
  • New Topic

servlet error

 
Reshma Reddy
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all i am running a servlet application on tomcat server it is showing 404 error but i checked in web.xml and in my jsp i didn't getting where exactly the problem getting

i am getiing this error
-----------------------

HTTP Status 404 - /FirstServlet

type Status report

message /FirstServlet

description The requested resource (/FirstServlet) is not available.

web.xml
--------
<web-app>

<display-name>Webapplication</display-name>
<servlet>
<servlet-name>FS</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FS</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SS</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SS</servlet-name>
<url-pattern>/SecondServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TS</servlet-name>
<servlet-class>ThirdServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TS</servlet-name>
<url-pattern>/ThirdServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Hello.jsp</welcome-file>
<!--<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
--></welcome-file-list>
</web-app>

Hello.jsp
----------
<HTML>
<HEAD>
<TITLE> Cookies Example </TITLE>
</HEAD>

<BODY bgcolor="#C0C0C0" >
<form action ="/FirstServlet" method="get" >

<h1><center><FONT COLOR="#CCFFFF">PERSONAL

DETAILS</FONT></center><h1>
<br><br>

<table align="center">
<center>
<tr>
<td>Enter Name:</td>
<td><input type="text" name="name" ></td>
</tr>
<tr>
<td>Enter Address:</td>
<td><input type="text" name="address"

></td>
</tr>
<tr>
<td>Enter Age:</td>
<td><input type="text" name="age" ></td>
</tr>
<tr>
<td><input type="Submit"

value="Continue"></td>
</tr>
</table>
</BODY>
</HTML>

please tell me where exactly i am getting problem

Thanks in advance.

 
Raghu ram
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Frnd,

404 error means its problem with path of your .class file and another thing is you should give the folder name before firstServlet.You have to copy the complete path of the .class file in the webapps folder in your tomcat. And paste it in the web.xml file.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Here is a few things you should take care of
  • Give your root a decent signature. In case you are using Servlets 2.4, here is one.
  • Put your servlets into packages. Leaving them in the default package may give unpredictable results.
  • Set the context into the html form's action. For example, if you use EL, ${pageContext.request.contextPath}/FirstServlet

  •  
    Jay Pagnis
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Hello,

    From the looks of it, everything is perfect. Except in the Hello.jsp following error exists:

    In the "form" line, the action points to "/FirstServlet". This will take the URL beyond the context root. eg to

    http://localhost:8080/FirstServlet

    To avoid this, remove the "/" before the "FirstServlet" in the form's action or add a contextpath as a part of the path. Here is how you can do this:

    1. Removing "/"

    <form action ="FirstServlet" method="get" >

    This is normally dangerous. Since the FirstServlet is searched in the relative path. So if your Hello.jsp happens to be in a folder, it will try to search for "FirstServlet" within that folder.

    2. Adding contextpath as a part of the path

    <form action ="<%=request.getContextPath()%>/FirstServlet" method="get" >

    This is the preferred method since the servlet is searched absolutely.

    Regards,
    Jay Pagnis
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Jay's answer is excellent.
    The only change I would make is to use EL instead of a scriptlet unless this is being written in a legacy version of JSP.



    For a very complete explanation of relative links in servlet apps, see:
    http://faq.javaranch.com/java/RelativeLinks
     
    Gobinath Manoj
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Hi,

    Everything was correct expect in your 'hello.jsp' form, just you remove the slash in front of <method="FirstServlet"> now it will work perfectly. Because in web.xml the urlpattern will take default "/", so it is not nessassary to put / in form action.
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Gobinath Manoj,
    Take a look at the two posts above yours to see why removing the forward slash, alone is not an optimal solution.
     
    Reshma Reddy
    Ranch Hand
    Posts: 197
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Hi to all,
    thanks for your replays
    i tried using this "<%=request.getContextPath()%>/FirstServlet"
    but i am getting same 404 classnot found error.why this jsp is not recognizing my servlet class.

    Ben i tried this also
    <form action ="${pageContext.request.contextPath}/FirstServlet" method="get" >

    but i am getting this error
    your not declared method getContext() in your servlet .
    [ December 05, 2007: Message edited by: vishnu vardhan ]
     
    Reshma Reddy
    Ranch Hand
    Posts: 197
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Thanks to all,
    i got where the exact problem is there.
    and i run my application successfully .....

     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Glad it's working for you.
    Welcome to the ranch.
     
    Reshma Reddy
    Ranch Hand
    Posts: 197
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Hi,
    Ben thanks for your posting

    Thanks,
    vardhan
     
    Arajeshh Kumara
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Hello,
    I followed these step but still i am getting same 404 error. I didn't understand the last step. Could you please describe once again..

    Thanks in Advance.
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Arajeshh Kumara,

    It would be better if you started a new thread.
    Most people won't bother reading to the bottom of a long thread that is almost a month old.

    When you do, please include:
  • The exact location of your servlet class
  • Your web.xml file's servlet entry and servlet mapping entry.
  • The URL or form action that you're using when trying to access your servlet


  • -Ben
     
      Bookmark Topic Watch Topic
    • New Topic