Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.web.servlet.PageNotFound Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.web.servlet.PageNotFound

    Hi, everyone. I met a problem while i try to do something in the web mvc template sts provide.

    the web.xml file is:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    </web-app>


    And the /WEB-INF/spring/appServlet/servlet-context.xml file is:

    <?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"
    xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <beansroperty name="prefix" value="/WEB-INF/views/" />
    <beansroperty name="suffix" value=".jsp" />
    </beans:bean>

    <beans:bean name="/home.htm" class="com.myresource.source.HomeController">
    <beansroperty name="greeting" value="Welcome here" />
    </beans:bean>
    </beans:beans>

    The com.myresource.source.HomeController class is :


    package com.myresource.source;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;

    /**
    * Handles requests for the application home page.
    */
    public class HomeController implements Controller{

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    private String greeting;

    public ModelAndView handleRequest(HttpServletRequest arg0,
    HttpServletResponse arg1) throws Exception {
    // TODO Auto-generated method stub
    return new ModelAndView("home","Message",greeting);
    }

    public void setGreeting( String greeting ){
    this.greeting = greeting;
    }
    }

    the home.jsp page is :

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ page session="false" %>
    <html>
    <head>
    <title>Home</title>
    </head>
    <body>
    <h1>
    ${Messge }
    </h1>
    </body>
    </html>


    while i try to use http://localhost:8080/Fan/home.htm, i got 404 status.
    And the error log from tomcat is :

    org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/Fan/home.htm] in DispatcherServlet with name 'appServlet'

    It would be a great appreciation if u can give me some hint about that.

  • #2
    Nobody

    Nobody?fffff

    Comment

    Working...
    X