无法通过spring安全性呈现.html而.jsp工作正常

时间:2014-01-02 09:57:18

标签: java html spring spring-mvc

问题:

我有一个简单的HTML登录页面,其中包含userIDPassword字段,并以html编写 代码如下所示:

<form class="login-box" name="loginForm" action="j_spring_security_check">
    <div class="login-wrapper">
        <div class="box">
            <div class="content-wrap">
                <div style="text-align:center"><img height="" width=""src="resources/images/demo.logo.000.jpg"></div>
                <h1>Login to <span><img height="" width=""src="resources/images/demo.logo.jpg"> <sup>TM</sup></span></h1>
                <input class="form-control" type="text" name="j_username" placeholder="User ID">
                <input class="form-control" type="password" name='j_password' placeholder="Password">
                <input class="login" type="submit" value="Sign in"  formmethod="post"/>

                <div class="alert alert-error">  
                    <!-- Error Messages here -->     
                </div> 

            </div>
        </div>
    </div>
</form> 

现在我通过拦截器调用此页面,但它将警告显示为:

WARNING: No matching handler method found for servlet request: path '/WEB-INF/pages/home.html', method 'GET', parameters map[[empty]]

并且finnalyy无法呈现服务器错误

**HTTP Status 404 -

type Status report

message

description The requested resource is not available.
VMware vFabric tc Runtime 2.9.2.RELEASE/7.0.39.B.RELEASE**

但是当我将Login.html更改为login.jsp时,它可以正常工作。 以下是我的xml配置

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

这是我的web.xml:

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
     <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                     /WEB-INF/mvc-dispatcher-servlet.xml
                     /WEB-INF/spring-security.xml
            </param-value>
            </context-param>
  </web-app>

弹簧security.xml文件:

<security:http>
    <security:intercept-url pattern="/welcome" access="ROLE_USER"/>
    <security:form-login login-page='/Login' default-target-url="/success" 
    login-processing-url="/j_spring_security_check"
    authentication-failure-url="/WEB-INF/pages/Login.jsp?error=true"/>
</security:http>
我错过了什么...... ??

3 个答案:

答案 0 :(得分:0)

好像你正在尝试访问WEB-INF目录中的html文件。您无法直接从浏览器访问WEB-INF内的任何资源。将html文件放入web资源文件夹,但在WEB-INF之外,然后重试。

答案 1 :(得分:0)

如果您仍然感兴趣,这是我的解决方案

在web.xml中添加: -

<servlet>
<servlet-name>Authenticate</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Authenticate</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<!-- SERVLET MAPPING FOR HTML -->

<servlet-mapping>
<servlet-name>Authenticate</servlet-name><url-pattern>*.html</url-pattern>  
</servlet-mapping>

在Authenticate-servlet.xml中添加

<mvc:resources mapping="/**" location="/WEB-INF/html/" />

将你的html文件放在web-inf / html文件夹中

答案 2 :(得分:0)

你能检查一下spring-security.xml中的条目吗?

authentication-failure-url="/WEB-INF/pages/Login.jsp?error=true"/>

不应该......

authentication-failure-url="/WEB-INF/pages/Login.**html**?error=true"/>