我是 Spring 新手,一直在关注http://viralpatel.net上的教程,目前Spring 3 MVC 存在问题:Tiles Plugin Tutorial
我已经在 google 和 stackoverflow 上搜索了一个解决方案,如果这是重复的,我找不到一个如此 appoligies 的解决方案。
当我尝试运行上述教程中的代码时,我基本上在浏览器中收到以下 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>
其余代码是上面教程的精确副本,它建立在处理表单教程的基础上,我似乎已经完美地工作了。下面是 Eclipse 中项目的屏幕截图,包括 jar,以防有人认为这可能是缺少或错误 jar 的问题
任何帮助/建议/指针将不胜感激。