我正在开发基本的spring项目并尝试实现自定义登录页面。但是当我尝试访问HTML页面时,它会给我错误"页面未找到"但是我的jsp页面可以从同一个位置访问(即ProjectName / webcontent / Sample.jsp)。为什么我无法访问html页面?
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 :(得分: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";