Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2011, 05:23 AM
Registered User
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTP STATUS 404 ERROR TOMCAT

Hi all,
I'm new to servlet to I'm testing my first servlet program but it is giving HTTP STATUS 404 error. The things which I have done are:
1> Installed java-> C:\Program Files\Java\jdk1.7.0
2> Installed Tomcat-> C:\apache-tomcat-7.0.23
3> When I type -> localhost:8080 in the browser it works fine.
4> Directory for the folder which I created-> C:\apache-tomcat-7.0.23\webapps\Hello
It contains a web.xml file and WEB-INF folder.
Inside WEB-INF, there is a folder named classes, which contains HelloServlet.class

The Souce code for my java file 'HelloServlet.java' is given below-

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletResponse response,HttpServletRequest request)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello bhai</title>");
out.println("<head>");
out.println("<body>");
out.println("<h1>Hey bhagwan ho jaye bus</h1>");
out.println("</body>");
out.println("</html>");
}
}

web.xml file code-

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>

</web-app>


After reading few suggestions I tried by changing url to /HelloServlet.htm (or .html) but still I get the same error message.
************************************************** ****
HTTP Status 404 - /Hello/HelloServlet.html

type Status report

message /Hello/HelloServlet.html

description The requested resource (/Hello/HelloServlet.html) is not available.
Apache Tomcat/7.0.23
************************************************** ****Log file catalina.2011-12-11 is-
Dec 11, 2011 8:25:59 AM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.22.
Dec 11, 2011 8:26:00 AM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].
Dec 11, 2011 8:26:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8080"]
Dec 11, 2011 8:26:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
Dec 11, 2011 8:26:07 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 9718 ms
Dec 11, 2011 8:26:07 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 11, 2011 8:26:07 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.23
Dec 11, 2011 8:26:07 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\docs
Dec 11, 2011 8:26:11 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,313] milliseconds.
Dec 11, 2011 8:26:11 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\examples
Dec 11, 2011 8:26:12 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\Hello
Dec 11, 2011 8:26:13 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\host-manager
Dec 11, 2011 8:26:13 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\manager
Dec 11, 2011 8:26:13 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.23\webapps\ROOT
Dec 11, 2011 8:26:13 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-apr-8080"]
Dec 11, 2011 8:26:13 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Dec 11, 2011 8:26:14 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6679 ms

Please help me out as soon as possible. I'll be very much thankful to you.

Regards-
Rahul
 
Old February 15th, 2012, 01:05 AM
Registered User
 
Join Date: Feb 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rahul,

When i see your program, it looks Hello/HelloServlet.html. Bur u didnot write HelloServlet.html page. So the server does not locating HelloServlet.html page.

Try with Hello/HelloServlet, dont use .html

See the below Example
Hello World Example

Last edited by Ram132; February 15th, 2012 at 01:09 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Status error 404 work but not 500 ? Rushino BOOK: Beginning ASP.NET 4 : in C# and VB 1 May 20th, 2010 03:04 PM
HTTP Status 404 - /TomcatProject/JSPDemo.jsp = ERROR gk03 Servlets 1 October 5th, 2009 01:15 AM
HTTP Status 404 rivcam JSP Basics 7 June 3rd, 2008 09:32 PM
HTTP status 404-Servlet action is not available matrixbegins Struts 0 October 24th, 2007 11:09 PM
HTTP status 404 brianjs JSP Basics 2 October 26th, 2003 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.