gpt4 book ai didi

java - 陷入 Spring MVC 新手教程

转载 作者:行者123 更新时间:2023-12-01 16:04:17 24 4
gpt4 key购买 nike

我被这个针对新手的 Spring MVC 教程困住了: http://sites.google.com/site/springmvcnetbeans/step-by-step/

我是第1.12点“试用应用程序”。当我在地址栏中输入 hello.htm 时,它不起作用,但 hello.jsp 可以工作。但我想重点是要以某种方式隐藏这个 JSP 扩展。

我严格按照教程进行操作。我可能做错了什么?

skaffman 建议发布 web.xml 和 servlet 映射 xml 文件,所以它们就在这里。我只添加了教程中所说的内容(但使用了另一个包名称,其余部分由 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>

最佳答案

我可以看到一些差异。本教程中的文件名为 springapp-servlet.xml,而不是 springsample-servlet.xml(请参阅步骤 1.8),并且它只包含一个 bean,即 hello.htm bean。整个过程中没有提到 springsample-servlet.xml

关于java - 陷入 Spring MVC 新手教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2961594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com