Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 404 not found(Servlet not found) [duplicate]

I am a student learning to build Web Application using jsp and servlets. My Web Application project was working fine since a month but today suddenly its behaving weird. When I am submitting my jsp page, it is not able to find my servlet. I have used servlet annotation to map the request.

Following is my jsp:-

<form name=registration_form action="<%=application.getContextPath() %>/Registration" method="post">  
    First Name:</td><td><input type="text" name="firstName" required/></td></tr> 
    </form>

Following is my Servlet:-

package servlets;
    @WebServlet("/Registration")
    public class Registration extends HttpServlet {
        private static final long serialVersionUID = 1L;
        public Registration() {
            super();
        }

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
        }

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String firstName=request.getParameter("firstName"); 
            System.out.println(firstName);
        }
    }

Following is my web.xml:-

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Login</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Following is my Project Hierarchy:-

enter image description here

Following is the error:-

HTTP Status 404 - /Login/Registration
type Status report

message /Login/Registration

description The requested resource is not available.

Apache Tomcat/7.0.47 

Following is my console log:-

Mar 11, 2014 11:30:33 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files (x86)/Java/jdk1.6.0_17/bin/../jre/bin/client;C:/Program Files (x86)/Java/jdk1.6.0_17/bin/../jre/bin;C:/Program Files (x86)/Java/jdk1.6.0_17/bin/../jre/lib/i386;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files (x86)\Java\jdk1.6.0_17\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Android\android-sdk;C:\Program Files (x86)\Java\jdk1.6.0_17\bin;C:\Program Files (x86)\MySQL\MySQL Utilities 1.3.4\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;D:\mongodb\bin;D:\development tools\apache-maven-3.1.1-bin\apache-maven-3.1.1\bin;C:\Program Files (x86)\Google\google_appengine\;D:\development tools\eclipse;;.
Mar 11, 2014 11:30:33 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Login' did not find a matching property.
Mar 11, 2014 11:30:34 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 11, 2014 11:30:34 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 11, 2014 11:30:34 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1071 ms
Mar 11, 2014 11:30:34 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 11, 2014 11:30:34 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Mar 11, 2014 11:30:35 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 11, 2014 11:30:35 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 11, 2014 11:30:35 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1463 ms
like image 629
Saumyaraj Avatar asked Mar 11 '14 05:03

Saumyaraj


People also ask

How do I fix HTTP Status 404 not found?

The simplest and easiest way to fix your 404 error code is to redirect the page to another one. You can perform this task using a 301 redirect. What's 301, you may ask? It's a redirect response code that signals a browser that the content has been transferred to another URL.

What is the meaning of 404 error in servlet?

The error code is HTTP 404 (not found) and the description is: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. This error means the server could not find the requested resource (JSP, HTML, images…) and returns HTTP status code 404.

Why does Tomcat say error 404?

This error indicates that the server could not find the desired resource. This resource can be any file such as JSP, HTML, or image resource. Usually, the resource is present, but it is referenced incorrectly. In most cases, you can fix this by correcting the URL.


2 Answers

I had suffered this problem too. Whenever we delete a tomcat server and run our project in new one without build classpaths and clean and build that project, we got this type of exceptions.

So, Build your projects classpath. Goto property of your Project then Select =>Java Build Path => Order and Export. Select All classpaths.

like image 117
Hardik Barot Avatar answered Sep 25 '22 04:09

Hardik Barot


Your Servlet path is /Registration but your request points to /Login/Registration.

You need to your form's action attribute to follow.

action="${pageContext.request.contextPath}/Registration"

or

action="/Registration"
like image 30
shazin Avatar answered Sep 23 '22 04:09

shazin