While using "/*" as url pattern in web.xml in spring mvc, I am not redirected to page. Whenever i try below urls, i am getting logger inside the controller methods but i am not getting the page.
Url tried : http://localhost:8080/mvc-example
Logger : Home Page Requested
Jul 02, 2019 3:57:35 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/mvc-example/WEB-INF/views/helloAgain.jsp] in DispatcherServlet with name 'mvc-example'
and
Url tried : http://localhost:8080/mvc-example/hello
Logger : Home hello Page Requested
Jul 02, 2019 3:58:38 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/mvc-example/WEB-INF/views/hello.jsp] in DispatcherServlet with name 'mvc-example'
This is my project structure :
My Controller :
@Controller
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(Locale locale, Model model) {
System.out.println("Home hello Page Requested");
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public String printAgainHello(Locale locale, Model model) {
System.out.println("Home Page Requested");
model.addAttribute("message", "Hello Again Spring MVC Framework!");
return "helloAgain";
}
}
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>mvc-example</display-name>
<servlet>
<servlet-name>mvc-example</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-example-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-example</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
mvc-example-servlet.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.khan" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
When i use "/" only then its working fine as expected but "/*" not working. Making some mistake i guess.
Any one please explain me this ?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire