4

当我穿上Tomcat 时,System.out.println@Controller在 Tomcat 控制台中看到了消息,但 Web 浏览器给了我The requested resource () is not available.

我的控制器:

@Controller
public class IndexPageController {
    @RequestMapping("/hello")
    public String homePage(Model model) {
        System.out.println("Controller method called"); // gets printed
        return "hello";
    }
}

我的视图解析器(在与此 URL 调度程序相关的 XML 中):

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

ViewResolver 是肯定创建的,因为如果我删除这个必需的属性,它会抛出关于 viewClass 的异常。

当然,存在/WEB-INF/jsp/hello.jsp文件。该文件也被正确部署(检查了tomcat运行时目录)。

在 中看不到任何异常tomcat_working_dir/logs,仅通过以下方式访问日志:

127.0.0.1 - - [01/Nov/2013:13:59:01 +0100] "GET /mvctest/hello HTTP/1.1" 404 952

从控制器返回“hello.jsp”不会改变任何东西。

调用其他 URL,而不是/hello给出完全相同的输出`The requested resource () is not available.

它看起来JstlView通过 AGAIN 转发到 JSP DispatcherServlet,当然调度程序不知道此类 URL 的映射

春季日志:

14:20:43.049 ["http-bio-8080"-exec-16] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/jsp/hello.jsp]] in DispatcherServlet with name 'SpringDispatcher'
14:20:43.049 ["http-bio-8080"-exec-16] DEBUG org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/jsp/hello.jsp] in InternalResourceView 'hello'
14:20:43.049 ["http-bio-8080"-exec-16] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'SpringDispatcher' processing GET request for [/mvctest/WEB-INF/jsp/hello.jsp]
14:20:43.050 ["http-bio-8080"-exec-16] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /WEB-INF/jsp/hello.jsp
14:20:43.050 ["http-bio-8080"-exec-16] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/WEB-INF/jsp/hello.jsp]
14:20:43.050 ["http-bio-8080"-exec-16] WARN  org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/mvctest/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'SpringDispatcher'

TRACE-leveled 日志:pastebin 原始文件

web.xml调度程序配置:

<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

没有其他人servlets也没有servlet-mappings,只有welcome-file-list

4

1 回答 1

5

问题来自您的调度程序 servlet 映射。由于 '/*' 映射,它也会拦截对您的 jsp 的请求。它应该是:

<servlet-mapping>
    <servlet-name>SpringDispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
于 2013-11-01T13:35:41.157 回答