0

I am working on basic spring project and trying to implement custom login page. But when I try to access HTML pages it gives me error "page not found" but my jsp pages are accessible from the same location(i.e ProjectName/webcontent/Sample.jsp). why am I not able to access html pages ?

web.xml is :-

<!-- 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>
user3640507
  • 65
  • 1
  • 7

1 Answers1

1

based on the information problem is with view resolver:

<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 is for JSP.

change it to:

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

Great answer to this problem can be found here too: How to serve .html files with Spring

EDIT 1: Since HTML is static you can use the following:

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

put your HTML files in webapp/static/ folder and when you return the view do the following for e.g.

return "index.html";
Community
  • 1
  • 1
Aeseir
  • 7,754
  • 10
  • 58
  • 107