【发布时间】:2012-02-01 12:10:39
【问题描述】:
基本上,当我启动我的项目时发生的情况是视图都已正确解析并且正在寻找正确的 jsp,但是似乎有一些东西阻止了对 WEB-INF 文件夹中我的 jsp 文件夹的访问。
确切的问题是,当我转到 localhost/FitterBlog/index.htm 时出现 404 错误:
The requested resource (/FitterBlog/jsp/layout/layout.jsp) is not available.
我有以下代码:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
调度程序-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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="com.fitterblog.controllers"/>
<context:annotation-config/>
<!-- tiles configuration -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView</value>
</property>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
tiles.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/jsp/layout/layout.jsp">
<put-attribute name="title" value="FitterBlog" />
<put-attribute name="header" value="/jsp/layout/header.jsp" />
<put-attribute name="nav" value="/jsp/layout/nav.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/jsp/layout/footer.jsp" />
</definition>
<definition name="index" extends="baseLayout">
<put-attribute name="body" value="/jsp/index.jsp" />
</definition>
</tiles-definitions>
MainController.java:
package com.fitterblog.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class MainController {
@RequestMapping(value="index.htm", method=RequestMethod.GET)
public ModelAndView index() {
return new ModelAndView("index");
}
}
我已经三重检查了所有 JSP 文件都位于正确的位置,因为得到 404 错误的 layout.jsp 文件位于 WEB-INF/jsp/layout/layout.jsp 中。
【问题讨论】:
-
你不应该把
放在那里
标签: spring jsp http-status-code-404 tiles