我被困在了这个针对新手的Spring教程:http://sites.google.com/site/springmvcnetbeans/step-by-step/
我是第1.12点“尝试申请”。当我输入地址栏hello.htm时,它不工作,但hello.jsp工作。但我想重点是隐藏这个JSP扩展。
我严格遵守了教程。我可能做错了什么?
skaffman建议发布web.xml和servlet映射的xml文件,所以它们就在这里。我只添加了教程中提到的内容(但是使用另一个包名,rest是由NetBeans生成的)
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>springsample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springsample</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>
springsample-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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="/hello.htm"
class="controllers.HelloController" />
</beans>
发布于 2010-06-02 21:34:07
我能看出几个不同之处。本教程中的文件名为springapp-servlet.xml
,而不是springsample-servlet.xml
(参见步骤1.8),它只包含一个bean,即hello.htm
bean。在整件事情的任何地方都没有提到springsample-servlet.xml
。
发布于 2010-06-02 21:56:59
本教程告诉您将该文件放置在webapp根web/hello.jsp中,但是您已经告诉spring在/webapp/jsp/hello.jsp中查找它,您是否将该文件移动到该文件夹中?您可以在/springsample/hello.jsp中找到它这一事实表明您没有。
https://stackoverflow.com/questions/2961594
复制相似问题