0
votes

I am programming a spring application using Request Mapping annotation. http://localhost:8080/SpringMVC/hello give a 404(The requested resource is not available).Logging data from server `No mapping found for HTTP request with URI [/SpringMVC/WEB-INF/jsp/helloView.jsp] in DispatcherServlet with name 'dispatcher'. Could someone help.

Project structure enter image description here

@Controller 
    @RequestMapping(value="/hello")
    public class HelloController 
    {
    @RequestMapping(method=RequestMethod.GET) 
    public ModelAndView sayHello() 
    {
    ModelAndView view=new ModelAndView("helloView","HelloMessage", "Welcome"); 
    return view; 
    }

    }

helloView.jsp

<html>
<head>
<title>Spring  Application</title>
</head>
<body>
   <h2>${HelloMessage}</h2>
</body>
</html>

web.xml

<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>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>

dispatcher-servlet.xml

<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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Scans the classpath of this application for @Components to deploy as beans -->

    <context:component-scan base-package="controller" />
    <mvc:annotation-driven />

    <bean id="jspViewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
    </bean>

</beans>
2
any log message in console?Abhishek Nayak

2 Answers

2
votes

you have forgot to add <context:annotation-config/> in dispatcher-servlet.xml, which activates various annotation's like: @Controller, @Component, @Service, @Repository ..

and make spring dispatcher as a Default Servlet by mapping to /, So that every request will endup in dispatcher servlet.

<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>
1
votes

your web.xml has dispatcher servlet with url pattern /* that practically maps everything!so, make that / and try out...