簡體   English   中英

為什么春季警告消息是“ org.springframework.web.servlet.PageNotFound”?

[英]Why spring warn message is“ org.springframework.web.servlet.PageNotFound ”?

我嘗試spring 3 mvc這個包是org.spring.test和代碼是

@Controller
@RequestMapping("/welcome")
public class WelcomeController {

private Logger logger = org.slf4j.LoggerFactory.getLogger(WelcomeController.class);


@RequestMapping(method = RequestMethod.GET)
public void welcome() {
    logger.info("Welcome!");
}
@RequestMapping("test1")
public void test1() {
    logger.info("test1!");
}
@RequestMapping("test2")
public void test2() {
    logger.info("test2!");
}
}

web.xml是:

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/*.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

最后一個mvc.xml是

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.spring.test" />
<!-- Configures support for @Controllers -->
<mvc:annotation-driven />

<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>

當我使用“ mvn jetty:run”命令並寫入http:// localhost:8080 / springdemo / welcome時

 "HTTP ERROR 404
Problem accessing /springdemo/WEB-INF/views/welcome.jsp. Reason:
 NOT_FOUND" 

控制台消息是:

INFO : org.spring.test.WelcomeController - Welcome!
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/springdemo/WEB-INF/views/welcome.jsp] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'

為什么?

看來您缺少/WEB-INF/views/test.jsp。 真的嗎?

您正在請求/ test URI,它未映射到您的控制器類(我認為是映射到/ welcome)。 Spring使用InternalResourceViewResolver服務您的請求。 它帶有前綴+“ test” +后綴。 這樣便可以得到/WEB-INF/views/test.jsp。

確保您擁有該JSP或更改您的控制器映射。

更新:好的,您更改了問題。 但是,您是否有/springdemo/WEB-INF/views/welcome.jsp?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM