java - spring mvc + 磁贴出现 404 错误,但没有控制台错误

标签 java spring-mvc tiles

我是 Spring 新手,一直在关注 http://viralpatel.net 上的教程目前 Spring 3 MVC: Tiles Plugin Tutorial 存在问题

我已经在 google 和 stackoverflow 上搜索了此问题的解决方案,但找不到解决方案,因此如果这是重复的,请进行应用。

当我尝试运行上述教程中的代码时,我基本上在浏览器中收到以下 404 错误

HTTP Status 404 - /Spring3MVC/WEB-INF/jsp/layout.jsp

但我没有收到控制台错误:

    01-Nov-2012 13:37:32 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C
:\Program Files\Java\jre1.6.0.33\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\oraclexe\app\oracle\product\11.2.0\server\bin;;C:\Windo
ws\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common F
iles\Intel\WirelessCommon\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Progra
m Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files (x86)\Microsoft Office 2010\Office14;C:\
Program Files (x86)\QuickTime\QTSystem\;C:\Python27\;C:\Python27\Tools\Scripts\;C:\Program Files\Java\jre1.6.0.33\bin;C:\Program Files\maven-2.2.1\bin
;.
01-Nov-2012 13:37:32 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Spring3MVC' did not find a m
atching property.
01-Nov-2012 13:37:32 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
01-Nov-2012 13:37:32 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 533 ms
01-Nov-2012 13:37:32 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
01-Nov-2012 13:37:32 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.36
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
01-Nov-2012 13:37:33 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
01-Nov-2012 13:37:33 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
01-Nov-2012 13:37:33 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
01-Nov-2012 13:37:33 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/27  config=null
01-Nov-2012 13:37:33 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1637 ms

这是我的 web.xml 文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID" version="2.5">
        <display-name>Spring3MVC</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>

        <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>spring</servlet-name>
            <url-pattern>*.html</url-pattern>
        </servlet-mapping>
    </web-app>

这是我的 spring-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: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/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <context:component-scan
        base-package="net.viralpatel.spring3.controller" />

    <bean id="viewResolver"
        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="base.definition"
        template="/WEB-INF/jsp/layout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
    </definition>

    <definition name="contact" extends="base.definition">
        <put-attribute name="title" value="Contact Manager" />
        <put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />
    </definition>
</tiles-definitions>

其余代码是上述教程的精确副本,它构建于 handling forms tutorial我似乎工作得很好。下面是 Eclipse 中项目的屏幕截图,包括 jar,以防有人认为这可能是丢失或错误 jar 的问题

eclipse project

任何帮助/建议/指示将不胜感激。

最佳答案

这可能是问题所在

在tiles.xml中,layout.jsp URL是

/WEB-INF/jsp/layout.jsp

你的jsp文件夹是

WebContent/jsp/

关于java - spring mvc + 磁贴出现 404 错误,但没有控制台错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13178781/

相关文章:

java - 自定义 map 条目集 - 可能吗?

java - 将传入的 JSON 映射到 Spring Boot 中的类

java - Spring MVC 中的错误 : java. lang.NoSuchMethodException : java. lang.Long.<init>()

java - Spring Data JPA 如何传递日期参数

java - osmdroid 中缺少图 block

java - 我们什么时候在 SQLException 中得到 "' NaN' is not a valid numeric or approximation numeric value”?

java - 使用 RX Java Operators 设计 API 流程

java - Springs MockMvc 以两种略有不同的方法之一返回空内容

javascript - 传单 map 未加载

spring - tilesConfigurer : java. lang.IllegalArgumentException:无法在没有 ServletContext 的情况下解析 ServletContextResource