File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes servlet error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

servlet error

Reshma Reddy
Ranch Hand

Joined: Dec 21, 2006
Posts: 197
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

Joined: Oct 19, 2007
Posts: 34
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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


  • [My Blog]
    All roads lead to JavaRanch
    Jay Pagnis
    Greenhorn

    Joined: Dec 04, 2007
    Posts: 2
    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

    Joined: Dec 11, 2004
    Posts: 13410

    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


    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
    Gobinath Manoj
    Greenhorn

    Joined: Oct 17, 2007
    Posts: 11
    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.


    Thanks Regards <br />Gobinath.L
    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    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

    Joined: Dec 21, 2006
    Posts: 197
    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

    Joined: Dec 21, 2006
    Posts: 197
    Thanks to all,
    i got where the exact problem is there.
    and i run my application successfully .....

    Ben Souther
    Sheriff

    Joined: Dec 11, 2004
    Posts: 13410

    Glad it's working for you.
    Welcome to the ranch.
    Reshma Reddy
    Ranch Hand

    Joined: Dec 21, 2006
    Posts: 197
    Hi,
    Ben thanks for your posting

    Thanks,
    vardhan
    Arajeshh Kumara
    Greenhorn

    Joined: Dec 29, 2007
    Posts: 12
    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

    Joined: Dec 11, 2004
    Posts: 13410

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: servlet error