HTTP Status 404 - /FirstSpringMVCProject/WEB-INFHelloPage/.jsp - spring-mvc

I am trying to learn the spring mvc framework but when I try to run the code underneat on the server, I am not getting anything rendered also only the error in the screen shoot. But I have noticed that the url has the following WEB-INFHelloPage/.jsp in the 404 error. Is that normal (also wihout backslash between WEB-INF/HelloPage.jsp)? And Why am I not getting something as:
First Spring MVC Application Demo
Hi user, welcome to the first Spring MVC Application
rendered?
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"
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>FirstSpringMVCProject</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HelloController class:
package com.stack;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class HelloController extends AbstractController {
#Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
ModelAndView modelandview = new ModelAndView("HelloPage");
modelandview.addObject("welcomeMessage", "Hi User, welcome to the first Spring MVC Application");
return modelandview;
}
}
spring-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="HandlerMapping"
class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean name="/welcome.html" class="com.stack.HelloController" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
HelloPage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- <title>Insert title here</title> -->
</head>
<h1> First Spring MVC Application Demo </h1>
<h2>${welcomeMessage}</h2>
<body>
</body>
</html>
screen shoot

The error is explicit about that: you forgot the ending / in prefix property. It should be:
...
<property name="prefix">
<value>/WEB-INF/</value>
</property>
...
But with a decent version of Spring MVC, you have no reason to use an explicit BeanNameUrlHandlerMapping nor derive you controller class from AbstractController. Those were for Spring 2.0, but since 3.1 RequestMapping annotated methods are both more powerful and simpler to use.

Related

How to resolve No mapping found for HTTP request with URI [/springmvc/hello] in DispatcherServlet with name 'dispatcher' error

I am getting 404 error when i try to launch my hello.jsp page, index.jsp page is working fine. But when i try to change the address from "http://localhost:8080/springmvc" to "http://localhost:8080/springmvc/hello", i get "HTTP Status 404 – Not Found" error on webpage.
I am trying to read the 'hello.jsp' page from separate folder i.e views under "WEB-INF/views/hello.jsp".
I recreated the whole project to find if there was any mistake.
***[MY WEB.XML CODE]***
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Hello Spring MVC</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
***[MY DISPATCH-SERVLET.XML FILE CODE]***
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.thomas.spring.springmvc.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
name="viewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
***[MY CONTROLLER CLASS CODE]***
package com.thomas.spring.springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HelloController {
#RequestMapping("/hello")
public ModelAndView hello()
{
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("hello");
return modelAndView;
}
}
***[MY HELLO.JSP FILE CODE]***
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Hello</title>
</head>
<body>
<h1>Hello from Spring MVC!</h1>
</body>
</html>
I expect the output to be getting message "Hello from Spring MVC!" from "hello.jsp" file. But i am getting "HTTP Status 404- Not Found".
Console output is " Sep 12, 2019 1:51:38 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/springmvc/hello] in DispatcherServlet with name 'dispatcher' ".

Tomcat 404 Http Not Found

I am learning Spring MVC and I build the first "hello world" example. But I can not reach the page. It says "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." I am using Tocat 9.0 (I also tried Tomcat 8 still not working). So here is my code below
Controller:
package com.emin.springdemo.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping("/")
public String showPage() {
return "main-menu";
}
}
jsp file:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>Spring MVC Demo</h2>
</body>
</html>
servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.emin.springdemo.mvc" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml:
[![<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I know there is a duplicate subjects in the site. I tried them also didn't reach the solution.
The problem might be the dash since it's not a valid a Java identifier Try renaming jsp and return fileName.
The page you're requesting from browser is not found, so you need to add URL in below pattern:
localhost:(Port number) /project name/(request mapping at controller) /(request mapping at method)
Try mapping URL and restart server.

Spring MVC No mapping found for HTTP request with URI /x/ in DispatcherServlet

I've seen this post with no solutions. I'm trying to run a Spring MVC tutorial but for some reason I'm not able to get the mapping in my servlet to call my home.jsp found in /WEB-INF/jsps directory. My context root is set to spring in Eclipse Web Project Settings. The error I'm getting is:
INFO 2016-11-06 11:18:59,613 [http-bio-8080-exec-3]
org.springframework.web.servlet.DispatcherServlet -
FrameworkServlet 'offers': initialization completed in 486 ms
WARN 2016-11-06 11:18:59,623 [http-bio-8080-exec-3]
org.springframework.web.servlet.PageNotFound
- No mapping found for HTTP request with URI [/spring/]
in DispatcherServlet with name 'offers'
My code is as follows:
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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>spring-tutorial-50</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>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<web:load-on-startup>1</web:load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
offers-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-
3.2.xsd">
<context:component-scan base-package="com.mypackage.spring.web.controllers">
</context:component-scan>
<mvc:annotation-driven />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
Controller:
#Controller
public class OffersController {
private Logger log = Logger.getLogger(OffersController.class);
#RequestMapping("/")
public String showHome(){
log.info("showHome() called");
return "home";
}
}
home.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Inside jsps</title>
</head>
<body>
Hi Mom!
</body>
</html>
You did NOT map /spring URI to the controller RequestMapping, look at the below code for the correct mapping:
#Controller
public class OffersController {
private Logger log = Logger.getLogger(OffersController.class);
//Map RequestMapping to /spring
#RequestMapping("/spring", method=RequestMethod.GET)
public String showHome(){
log.info("showHome() called");
return "home";
}
}
I just upgraded to Spring 3.2.17 for all of my Maven library references. When I cleaned and redeployed It worked! #RequestMethod("/") by itself will work if the server is configured properly. It is also possible to get more explicit on what a RequestMethod can handle with things like the following: #RequestMethod(value="/spring", method = RequestMethod.GET) as #javaguy lists. value = "/" etc. also works.

Spring MVC request not reaching Controller class

I know this question has already been asked before, but none of the solutions mentioned there seems to be working for me.
I'm writing a Spring MVC web application. But my request is not reaching the controller class.
Here are the relevant files.
Can anyone please help me by pointing out where I am going wrong? Thanks...
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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>booksWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:**/*applicationContext.xml</param-value>
</context-param>
</web-app>
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Declare a view resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"/>
</bean>
</beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.booksworld.controllers" />
<context:annotation-config />
<mvc:annotation-driven />
<context:property-placeholder location="classpath:**/*config.properties" />
<!-- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="resources/Messages" /> -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory- ref="sessionFactory" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="packagesToScan" value="com.booksworld"></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
p:username="${jdbc.username}" p:password="${jdbc.password}" >
</bean>
</beans>
My controller class
package com.booksworld.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class CommonController {
#RequestMapping("/proceed")
public String loadLoginPage() {
System.out.println("we reached here");
return "login";
}
#RequestMapping(value="/login")
public String login() {
return "abc";
}
}
index.jsp (the welcome jsp file)
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO- 8859-1" %>
<!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=ISO-8859-1">
<title>Welcome All</title>
</head>
<body>
<p>Hello World</p>
<%response.sendRedirect("proceed.do"); %>
</body>
</html>
login.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<!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=ISO-8859-1">
<title>Books World - Login</title>
</head>
<body>
<sf:form method="POST" action="login.do" modelAttribute="Login">
<h3>Please enter your credentials</h3>
Login Name<sf:input path="userName" />
Password<sf:password path="password" />
</br>
</br>
<input type="submit" value="Log In" />
<input type="reset" value="Reset" />
</sf:form>
</body>
</html>
I'm developing in eclipse, and using Tomcat. the server log has no errors. Just the standard start-up log.
Please help me to point out where I am going wrong.
You haven't specified which URL you are hitting and what errors or output you are seeing so I will go by the files you have posted. There seem to be at least a few problems with what you have posted. I am assuming you are trying to access either http://[server]:[port]/index.jsp or http://[server]:[port]/.
Problem 1: When using an MVC framework you usually do not request web templates such as JSP files directly. Therefore, your welcome file list in web.xml should not contain index.jsp. It is more common to omit this section altogether. Instead, you should add a request mapping to the controller class for the application root, such as:
#RequestMapping("/")
public String home() { return "index"; }
Once you do this, you should be able to hit http://[server]:[port]/ and get a response.
Problem 2: The file index.jsp redirects to the URL proceed.do but there is no mapping for this URL in your controller. Instead, the controller has a mapping for the URL proceed. May be there was some confusion with Struts when you were trying to configure the URL mappings.
Problem 3: The file login.jsp submits to login.do but there is no mapping for this URL. Instead there is a mapping for login. The form action should therefore be changed from login.do to login.
Problem 4: The form in login.jsp is bound to a model attribute called Login but the controller does not add any model object with that name.
Problem 5: The form in login.jsp is submitted using an HTTP POST but the controller does not specify this for the login method. The default for controller methods annotated with #RequestMapping is HTTP GET so the login method will not be called when you submit the form.
Problem 6: The file index.jsp seems to be redundant as its sole purpose is to redirect to a different URL on the same server. You will be better off with the following simplified controller code:
#Controller
public class CommonController {
#RequestMapping("/")
public String loadLoginPage(Model model) {
model.addAttribute("Login", new Login()); // Or something like this, which represents the actual model object that should collect the login information.
return "login";
}
#RequestMapping(method = RequestMethod.POST, value="/login")
public String login(Login login) {
// Use the login object to authenticate the user.
return "abc";
}
}
I would also recommend that you keep the lines
<context:component-scan base-package="com.booksworld.controllers" />
<context:annotation-config />
<mvc:annotation-driven />
in the file dispatcher-servlet.xml as these lines are specific to your presentation layer.

java.lang.ClassNotFoundException: com.springframework.web.servlet.DispatcherServlet

I am trying to build up a simple spring mvc application,
but i am not able to run this application. After running project,
at the time, when tomcat server starts, it throws java.lang.ClassNotFoundException. Although index.jsp runs, but the execution terminates with 404 error after clicking on any hyperlink on this jsp page.
I have added all the required jar files, and eclipse gives autosuggestion for this class ie "DispatcherServlet". Any suggestion?
For reference, i am giving code too,
java.lang.ClassNotFoundException: com.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
================================================================================
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Spring App HomePage</title>
</head>
<body>
Say Hello
</body>
</html>
=======================================================================
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"
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>SpringMVC</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>com.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
==================================================================================
bean configuration file, spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="kumar.saroj.mvc" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
===========================================================================
Controller Class
package kumar.saroj.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HelloWorldController
{
public HelloWorldController()
{
}
#RequestMapping("/hello")
public ModelAndView helloWorld()
{
String message = "Hello World, Spring 3.2!";
return new ModelAndView("hello","message",message);
}
}
The DispatcherServlet class name is incorrect.
Try org.springframework.web.servlet.DispatcherServlet instead of com.springframework.web.servlet.DispatcherServlet in your web.xml.

Resources