Spring Security登录页面抛出ClassNotFoundException

时间:2013-08-05 17:08:25

标签: jsp spring-mvc spring-security

我正在尝试创建一个简单的Spring Security登录页面,所有配置对我来说都是正确的(实际上尝试了不同配置的声音。但失败了)。启动Tomcat时会抛出:

java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.pages.welcome_jsp

检查工件后,它似乎成功加载welcome.jsp页面,但当我尝试登录并提交tomcat尝试重定向并失败时:

HTTP Status 404 - /j_spring_security_check

同时将login-processing-url="/j_spring_security_check.action"更改为login-processing-url="/j_spring_security_check"成功登录但仍然当我输入错误的用户名时,传递错误页面失败(浏览器上的网址说: http://localhost:8080/welcome?login_error=-1):

HTTP Status 404 - /welcome

页面位于WEB-INF/pages文件夹下,共有2页index.jspwelcome.jsp

弹簧-config.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:security="http://www.springframework.org/schema/security"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <security:debug />

    <security:global-method-security jsr250-annotations="enabled" pre-post-annotations="enabled" secured-annotations="enabled" />

    <security:http use-expressions="true" authentication-manager-ref="authManager">
        <security:intercept-url pattern="/index" access="isAuthenticated"/>
        <security:intercept-url pattern="/welcome" access="permitAll"/>
        <security:form-login login-processing-url="/j_spring_security_check.action" login-page="/welcome" default-target-url="/index" authentication-failure-url="/welcome?login_error=-1" />
        <security:logout logout-success-url="/" delete-cookies="JSESSIONID" invalidate-session="true"/>
        <security:remember-me />
        <security:session-management invalid-session-url="/">
            <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="false" />
        </security:session-management>
    </security:http>

    <security:authentication-manager id="authManager">
        <security:authentication-provider>
            <security:jdbc-user-service data-source-ref="dataSource"
                                        users-by-username-query="
                select ..."

                                        authorities-by-username-query="
              select ...  "
                    />
        </security:authentication-provider>
    </security:authentication-manager>

    <context:component-scan base-package="com.ch.core"/>

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

    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="..." />
        <property name="username" value="..." />
        <property name="password" value="..." />
    </bean>

    <mvc:annotation-driven />

    <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/>

    <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>

    <mvc:resources mapping="/img/**" location="/img/" cache-period="31556926"/>

    <!-- Allows for mapping the DispatcherServlet to "/" by forwarding static resource
    requests to the container's default Servlet -->
    <mvc:default-servlet-handler/>

    <mvc:view-controller path="/welcome" view-name="welcome"></mvc:view-controller>

</beans>

相关 welcome.jsp 代码:

 <form name='f' class="navbar-form pull-right" action='/j_spring_security_check' method='POST'>
                        <input type='text' name='j_username' value=''>
                        <input type='password' name='j_password'>
                        <button name="submit" type="submit" class="btn btn-small">Log in</button>
                        <label id="rememberMe">
                            <input type="checkbox" name='_spring_security_remember_me'> <h6">Remember me</h6>
                        </label>
                    </form>
                    <c:if test="${not empty param.login_error}">
                        <div class="error">
                            Your login attempt was not successful, try again.<br />
                            Reason: ${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}
                        </div>
                    </c:if>

感谢您的帮助。

Spring Security 3.1.2,Spring WEBMVC 3.2.0,Tomcat 7.0.33。

0 个答案:

没有答案