HTTP Status 404 – Not Found on Tomcat server

Sayantan Chatterjee

I'm creating new spring mvc Dynamic Web Project on Eclipse version 4.9.0 Java EE IDE for Web Developers. I'm setting up a new Server Tomcat version 9.0.8. When I select hello.jsp and right-click ->Run As -> Run on Server, then hello.jsp works fine,and I access helo.jsp. But When I select project root folder and right-click ->Run As -> Run on Server, then it shows HTTP Status 404 with description:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.'

here is my Web.xml:

     <web-app id = "WebApp_ID" version = "2.4"
       xmlns = "http://java.sun.com/xml/ns/j2ee" 
       xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee 
       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>
    <servlet>
       <servlet-name>HelloWeb</servlet-name>
       <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
       <servlet-name>HelloWeb</servlet-name>
         <url-pattern>/</url-pattern>
     </servlet-mapping>
     <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>

Here is my full HelloWeb-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
  xmlns:context = "http://www.springframework.org/schema/context"
  xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation = "http://www.springframework.org/schema/beans     
  http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-4.3.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc.xsd">

  <context:component-scan base-package="com.tutorialspoint"/> 
  <mvc:annotation-driven/>

  <bean name="jspViewResolver" 
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WebContent/views/"></property>
    <property name="suffix" value=".jsp"></property>
  </bean>

</beans>

And here is my Controller:

package com.mypackage;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;

@Controller
public class HelloController {
   @RequestMapping(path="/hello",method = RequestMethod.GET)
   public String printHello(ModelMap model) {
      model.addAttribute("message", "Hello Spring MVC Framework!");
      return "hello";
   }
}

Here's my directory structure: https://imgur.com/CHKEsJo

here's my hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="ISO-8859-1">
    <title>Hello World</title>
  </head>
  <body>
     <h2>done!!!</h2>
     <h2>${message}</h2>
  </body>
</html>

My server.xml on Tomcat version 9.0.8 is remained as it is. I haven't changed anything. Only thing I have changed the HTTP/1.1 port,AJP/1.3 port and Tomcat admin Port.

What's wrong with here and what's the reason for this? I can't find out why. Can anyone point my mistake here?

Nicholas K

Try moving the folder views under the /WEB-INF/ and then change your HelloWeb-servlet.xml accordingly.

Also, make sure you are using this url to hit the resource :

http://localhost/Latest/hello

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Status: 404-Not found

HTTP Status 404 – Not Found: for controller - no view resolvers found in Idea

HTTP Status 404 - on Eclipse with Tomcat (with no generated web.xml)

HTTP Status 404 - Servlet not found

Servlet: HTTP Status 404 - Not Found

How to redirect "HTTP Status 404 – Not Found" to an error information page in tomcat?

Tomcat server, change default HTTP 404?

HTTP Status [404] ? [Not Found] (The origin server did not find a current representatio)

Maven web project HTTP Status [404] – [Not Found]

JAX-RS Rest service giving "HTTP Status 404 – Not Found" error tomcat while accessing in docker

HTTP Status 404 Not Found For Jersey REST application with Eclipse and Payara server

HTTP Status 500 – Internal Server Error-JSP-Tomcat server

HTTP Status 404 – Not Found tomcat spring

Http Status 404 after installing Tomcat 9

HTTP Status 404 – Not Found Spring Boot

HTTP Status 404 Tomcat Apache

tomcat changes 404 status into 403 for http delete

http status 404 hello.jsp (apache tomcat 6)

JSP/JDBC: HTTP Status 404 - Not Found

Why am I getting HTTP Status 404 - Not Found?

Tomcat 8 Http status 404 The requested resource is not available

Insertion of image in mysql using jsp HTTP Status 404 not found

Apache Tomcat 9 - HTTP Status 404 on browser

HTTP Status [404] ? [Not Found] for /login in spring security

Spring Mvc get HTTP Status [404] – [Not Found] after the submission

Spring Mvc App get - HTTP Status [404] – [Not Found]

HTTP Status 404 - Not Found - Servlet and JSP

Eclipse & Tomcat Error: HTTP Status 404 – Not Found:

HTTP 404 status code (Not Found) shown as 302