• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Status 404 - /WebApp/jsp/Servlet1

 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you get output? You get the response's Writer but don't write anything to it.
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a JDBC issue that should be addressed with a post in the appropriate forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic