2010-06-02 40 views
0

我被困在這個Spring MVC的教程新手滯留: http://sites.google.com/site/springmvcnetbeans/step-by-step/在Spring MVC的教程新手

我點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> 
+0

向我們展示您的'web.xml'和'springapp-servlet.xml'文件。 – skaffman 2010-06-02 21:08:46

回答

1

我什麼教程可以看到幾個不同點。本教程中的文件被稱爲springapp-servlet.xml,而不是springsample-servlet.xml(請參閱步驟1.8),它只包含一個bean,即hello.htm bean。整個事情的任何地方都沒有提及springsample-servlet.xml

+0

那麼我把它重命名爲SpringSample – AspNewbie 2010-06-02 21:42:04

+0

但我使用Java EE 6,傢伙使用Java EE 5。 現在我正確地重命名它,並用教程中的那些文件替換它們,以及它不會編譯,失敗:< nbdeploy clientUrlPart =「$ {client.urlPart}」debugmode =「false」forceRedeploy =「$ {forceRedeploy}」/> – AspNewbie 2010-06-02 21:48:48

+0

並且我還使用GlassFish 3而不是GlassFish 2 UR1 – AspNewbie 2010-06-02 21:50:45

0

本教程告訴您將文件放置在webapp根目錄web/hello.jsp中,但您已告訴spring在/WEB-INF/jsp/hello.jsp中查找它是否將該文件移動到該文件夾​​中?你可以在/springsample/hello.jsp找到它的事實表明你沒有。

+0

寫這篇教程的人還沒有:O – AspNewbie 2010-06-02 22:02:04

+0

他的第1.6節中的springapp-servlet.xml沒有像你的那樣覆蓋viewResolver。 – Affe 2010-06-02 22:05:46

+0

ahh 好吧我要完成他的應用程序的克隆:( – AspNewbie 2010-06-02 22:10:41