Hi ...
My Company gives me a task to learn about Spring Framework MVC and ORM Modules and evaluate if we can implement it in our tasks in the future ..
i began with code :
Code:<servlet> <servlet-name>springapp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springapp</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>Code:<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.xsd"> <bean name="hello.htm" class="springapp.web.HelloController" > </bean> </beans>Code:package springapp.web; import javax.servlet.http.*; import javax.servlet.ServletException; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; import java.io.IOException; import java.util.Date; public class HelloController implements Controller{ protected Log logger = LogFactory.getLog(getClass()); @Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String now = (new Date()).toString(); logger.info("======== to Hello.jsp modle it then view it "+now+"==="); return new ModelAndView("hello.jsp", "now", now); } }and the result when i run the url "http:localhost:8080/SpringApp/hello.htm" isCode:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!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> <h1>Spring Tutorial</h1> <p>Greetings <c:out value="${now}"></c:out></p> </body> </html>
Code:org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/SpringApp/hello.htm] in DispatcherServlet with name 'springapp'


Reply With Quote