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 HTTP Status 404 - /WebApp/jsp/Servlet1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 404 - /WebApp/jsp/Servlet1" Watch "HTTP Status 404 - /WebApp/jsp/Servlet1" New topic
Author

HTTP Status 404 - /WebApp/jsp/Servlet1

Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Servlet1.java

Source: \WebApp\src\java\Servlet1




web.xml

Source: \WebApp\web\WEB-INF\web.xml



ERROR:
HTTP Status 404 - /WebApp/jsp/Servlet1
type Status report

message /WebApp/jsp/Servlet1

description The requested resource (/WebApp/jsp/Servlet1) is not available.

Apache Tomcat/7.0.14

This error is driving me crazy. Tried everything. Please help.
Vijayamoorthi Periasamy
Greenhorn

Joined: Feb 13, 2008
Posts: 3
As per your current web.xml definition, you need to give the URL "/WebApp/Servlet1" to access Servlet1.

Since, you gave the welcome page as <servername>/WebApp/jsp/addinfo.jsp, when you submit the page the request URL "<servername>/WebApp/jsp/Servlet1" is constructed and sent to server. Since web.xml is not having any server mapping for the pattern "/jsp/Servlet1", you are getting the 404 response.

Change the web.xml as mentioned below

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/jsp/Servlet1</url-pattern>
</servlet-mapping>
<session-config>

</session-config>
<welcome-file-list>
<welcome-file>/jsp/addinfo.jsp</welcome-file>
</welcome-file-list>

</web-app>
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Thank you VijayaMoorthi. I, no longer get the error but I also don't get the output.
Where is the code going wrong?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Why would you get output? You get the response's Writer but don't write anything to it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

What I meant to say was, why is it happening so? I'm not able to write in my table.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5


ALL classes used in servlets MUST be placed in a package and the class files placed in the web app accordingly.

The reason being that the JVM looks for classes not in a package in the "current" directory, something you have no control over in a servlet environment.

Bill

Java Resources at www.wbrogden.com
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

The servlet is in a default package, so I didn't mention it in web.xml. Im using Netbeans IDE 7.0.1.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Noopur Kore wrote:The servlet is in a default package,

Then move it to a package other then the default. Did you not read the replies carefully?

Please see the ServletsFaq for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Okay. I tried what you guys told me. Made changes in web.xml. Named the package proservlet. Still no avail.
Here I'm adding few excerpt from my JSP page. Please Check.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Your action is wrong. See the JspFaq. Your action URL should be server-relative; that is, starting with the web application's context path.
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

This is so confusing. Can someone please help me out and show me what to do?
I'm trying since long and I am new to using IDEs or even Web Applications for that matter. I'm putting up all the details. Please someone show me, what needs to be done.

Here's the place where my servlet is located: C:\Users\Noopur\Studies\WebApp\src\java\proservlet\Servlet1. This is a Java file while the class file is located in WEB-INF.
I made a package named proservlet.

These are the changes I did in my web.xml file.



This are excerpts of my JSP file.


And my servlet is same as above except that now i have kept it under

Someone please give me a exact answer, this is very frustrating. Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Good news! You've already been given the answer. You need to precede the servlet path with the context path. The JspFaq outlines exactly how to do this.

P.S. I know you requested the exact answer, but that's not going to help you as much as learning how to look things up on your own.
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Okay Bear. I told you its confusing me. The context path is the place where I have kept the servlet, right? So the servlet is now in proservlet. I changed the path now and its saying broken link. Can you please give me a direct answer? And help me understand it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

The context path is the identifier used to differentiate the multiple web apps that can be deployed in a container.

In a JSP, it can be obtained with ${pageContext.request.contextPath}

It should be used for all URLs to resources in the web app.
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Okay, that resolves it. Thank you bear. But can you please tell me why am I still not able to write in my DB table?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

That's a JDBC issue that should be addressed with a post in the appropriate forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Status 404 - /WebApp/jsp/Servlet1
 
Similar Threads
A page not found error
not getting responce from Servlet
JDBC code with type 1 driver not working
please help with tomcat, javabean and jsp
problem with code