I am new to Spring. I have created a project using Spring 4.1 but unfortunately my http mapping not working with Dispatcher. Here is the code for my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<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>*.htm</url-pattern>
</servlet-mapping>
</web-app>
Disptcher Servelet xml code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1CZCNBy">
<bean name="./hello.htm" class="com.practice.controller.HelloController" />
</beans>
Controller code:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.practice.controller;
/** * * @author david */
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import java.io.IOException;
public class HelloController implements Controller {
static Logger logger = Logger.getLogger(HelloController.class);
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.info("Returning hello view");
return new ModelAndView("hello.jsp");
}
}
Unfortunately system is unable to map my request to controller.
Aucun commentaire:
Enregistrer un commentaire