2014-07-14 106 views
0

我正在開發基本的Spring項目並嘗試實現自定義登錄頁面。但是當我嘗試訪問HTML頁面時,它給了我錯誤「找不到頁面」,但是我的jsp頁面可以從同一位置訪問(即ProjectName/webcontent/Sample.jsp)。爲什麼我無法訪問html頁面?無法訪問HTML頁面但可訪問JSP頁面

的web.xml是: -

<!-- Spring Security --> 
<filter> 
<filter-name>filterChainProxy</filter-name> 
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
<filter-name>filterChainProxy</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 



<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<welcome-file-list> 
<welcome-file>Sample1.html</welcome-file> 
</welcome-file-list> 

的security.xml

<security:http auto-config='true' use-expressions="true" authentication-manager- ref="FormBasedAuthenticationManager" > 

<security:intercept-url pattern="/**" access="isAuthenticated()" /> 

</security:http> 




<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> 
<security:filter-chain-map path-type="ant"> 
<security:filter-chain pattern="/**" filters="springSecurityFilterChain" /> 
</security:filter-chain-map> 
</bean> 


</beans> 

sevlet.xml

<context:component-scan base-package="XYZ" /> 
<Secured:global-method-security secured-annotations="enabled" pre-post-annotations="enabled" jsr250-annotations="enabled"/> 
<mvc:annotation-driven /> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
<property name="prefix" value="/WEB-INF/"/> 
<property name="suffix" value=".html"/> 
</bean> 
+0

您可以發佈您的視圖解析器代碼,看看你是如何配置? – Aeseir

+0

@Aeseir我已經更新了 – user3640507

+0

,所以你的html文件位於/ WEB-INF /文件夾中,沒有其他子文件夾? – Aeseir

回答

1

基於該信息的問題是與視圖解析器:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
<property name="prefix" value="/WEB-INF/"/> 
<property name="suffix" value=".html"/> 
</bean> 

JSTLView適用於JSP。

將其更改爲:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/"/> 
    <property name="suffix" value=".html"/> 
    </bean> 

大回答這個問題,可以在這裏也可以找到:How to serve .html files with Spring

編輯1: 由於HTML是靜態的,你可以使用以下命令:

<mvc:resources mapping="/static/**" location="/static/" /> 

將您的HTML文件放在webapp/static /文件夾中,當您返回視圖時,請執行以下操作

return "index.html"; 
+0

即使在上面的格式修改它不工作的bean後。我們是否需要進行其他更改? – user3640507

+0

此外,我以前使用viewResolver第一次使用JSP頁面,並沒有要求任何解析器。所以我想知道爲什麼它需要爲HTML頁面 – user3640507

+0

添加靜態頁面的額外信息。 – Aeseir