如何使用純html頁面構建Spring MVC應用程序?當我在我的tomcat 7服務器上部署jsps時,它可以很好地映射頁面。但對於html,頁面不顯示。我收到404錯誤。如何在spring mvc中不使用jsps?請詳細說明我需要採取的步驟。使用Spring MVC的純HTML頁面應用程序
預先感謝您。
如何使用純html頁面構建Spring MVC應用程序?當我在我的tomcat 7服務器上部署jsps時,它可以很好地映射頁面。但對於html,頁面不顯示。我收到404錯誤。如何在spring mvc中不使用jsps?請詳細說明我需要採取的步驟。使用Spring MVC的純HTML頁面應用程序
預先感謝您。
在Spring MVC所有的請求經過FrontController - DispatcherServlet的
有你需要告訴Spring allowe JSP和HTML都在你的情況
例
dispatcher-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-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<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" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="/*.htm" class="controller.MyController"/>
</beans>
我沒有了解這個parameterizedViewController是什麼。還有什麼處理bean名稱'「/ *。htm」'?你能否詳細說明你的答案?我對春天很陌生。請向我解釋你提供的xml是怎麼回事 –
我希望有一個解釋。你能諮詢一下嗎? –
Thymeleaf會成爲你的朋友 http://www.thymeleaf.org/
please chang e將視圖解析器後綴添加到.html,以便viewResolver可以呈現您的視圖。
在答案中有一些建議[這裏](http://stackoverflow.com/questions/870150/how-to-access-static-resources-when-using-default-servlet) – GriffeyDog