Results 1 to 7 of 7

Thread: 404 Error

  1. #1
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default 404 Error

    I simply created a Dynamic Web Project named Redirect.
    Added the servlet jar file to the class path.
    Created a servlet, put it in a package called controller and named the class Controller.

    I hit run to make sure it worked and I get a 404 error. I added the web.xml file in the wizard too.

    Java Code:
    Error 404 - Not Found
    
    No context on this server matched or handled this request.
    Contexts known to this server are:
    Self validating Form(/Self_validating_Form)
    PageRedirect(/PageRedirect)
    Java Code:
    package controller;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class Controller
     */
    public class Controller extends HttpServlet {
    	private static final long serialVersionUID = 1L;
    
        /**
         * Default constructor. 
         */
        public Controller() {
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    	}
    
    }
    I was hoping I could get some advice because am I perplexed on why those above steps work on other computers but not this one. I am not doing anything different.

  2. #2
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: 404 Error

    I restarted eclipse and now I get the following error:

    Java Code:
    HTTP ERROR 404
    
    Problem accessing /Redirect/Controller. Reason:
    
        Not Found
    My URL is also correct....
    Last edited by jocdrew21; 01-11-2015 at 11:15 AM.

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    384
    Rep Power
    10

    Default Re: 404 Error

    What does your web.xml file look like?

  4. #4
    jocdrew21 is offline Senior Member
    Join Date
    Jan 2014
    Posts
    137
    Rep Power
    0

    Default Re: 404 Error

    Sorry I have not posted quicker. I have been really trying to get thing thing to work. Ok so I have made a lot of changes and I am getting new errors. I noticed I was using a different server and switched it to Tomcat and made sure it has the jstl.jar file in it. Then I added the jstl to the class path and manually put it in the WEB-INF-> lib folder. However I am getting the following error:

    Java Code:
    HTTP Status 500 - Servlet.init() for servlet jsp threw exception
    
    type Exception report
    
    message Servlet.init() for servlet jsp threw exception
    
    description The server encountered an internal error that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: Servlet.init() for servlet jsp threw exception
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	java.lang.Thread.run(Thread.java:744)
    my Code
    Java Code:
    <%@ page language="java" contentType="text/html; charset=US-ASCII"
        pageEncoding="US-ASCII"%>
        
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
    <!--Location of Css file-->
    <link rel="stylesheet" href="css/format.css" type="text/css"  />
    
    <title>Insert title here</title>
    </head>
    <body>
    
    <div id="intro">
    	<table border="1">
    	<tr>
    		<th>1</th>	
    		<th>2</th>
    		<th>3</th>
    	</tr>		
    	<tr>
    		<td>One</td>
    		<td>Two</td>
    		<td>Three</td>
    	</tr>
    	</table>
    </div>
    
    <jsp:useBean id="id" class="beans.Bean" scope="page"></jsp:useBean>
     
    <p>From the bean: <c:out value="${id.message}" /></p>
    
    </body>
    </html>
    web.xml
    Java Code:
    <?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"
      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>FirstJSTL</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      
    </web-app>
    I have been at this for over a week and am going in circles. Also I looked at my Java Resources->Libraries-> JRE System Library folder and it says JavaSE [1.7.0_45] which I found odd because I am using JavaEE. I then downloaded JavaEE 7 from the Oracle page just to make sure and after I downloaded the file a "Glassfish" file was displayed. I then put it in my computers directory made a new file call JAVA_HOME and threw the Glassfish file in there thinking it is the JavaEE JDK. When I tried to add it to eclipse preferences->java->installed JRE's and selected the above file mentioned it did not recognize it as a JDK.

    Now I am a bit lost and not sure where to go from here.

  5. #5
    hellogayathri is offline Member
    Join Date
    Jul 2015
    Posts
    3
    Rep Power
    0

    Default Re: 404 Error

    Hi,
    If u need run that project u must map that controller in web.xml
    Because whenever the request came to server first it should find it in web.xml.
    <servlet>
    <servlet-name>Controller</servlet-name>
    <servlet-class>Controller</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>Controller</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    add this piece of code in your web.xml and try.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    11

    Default Re: 404 Error

    That's one way that is pretty much legacy, nowadays you can just do it with an annotation and not bother with the web.xml so much.

    Java Code:
    @WebServlet("/hello")
    public class Controller extends HttpServlet {
    
    }
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    hellogayathri is offline Member
    Join Date
    Jul 2015
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •