• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HTTP Status 404 - /WebApp/jsp/Servlet1

 
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you get output? You get the response's Writer but don't write anything to it.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a JDBC issue that should be addressed with a post in the appropriate forum.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic