0

在 Tomcat 7 中运行项目时出现 404 错误。

弹簧安全:

<beans xmlns:p="http://www.springframework.org/schema/p"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
    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">
    <!-- <beans:import resource="Employee-servlet.xml"/> -->

    <security:http use-expressions="true">
        <intercept-url pattern="/Springhib/index.jsp/" access="permitAll" />

        <intercept-url pattern="/Springhib/jsp/login.jsp"
            access="permitAll" />
        <form-login login-page="login.jsp" default-target-url="/welcome.jsp"
            authentication-failure-url="/error.jsp" />
        <logout invalidate-session="true" logout-url="/logout.jsp" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"
                users-by-username-query="select username,password enabled from userlogin where username= ?" />
        </security:authentication-provider>
    </security:authentication-manager>

</beans>

Employee-servlet.xml : 它包含数据源(MySQL)、休眠事务管理器(休眠配置)和内部视图解析器

网页.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>SprinHib</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>

    </welcome-file-list>
    <servlet>
        <servlet-name>Employee</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>

    </servlet>

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

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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/Employee-servlet.xml,
        /WEB-INF/spring-security.xml
        </param-value>

    </context-param>
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

    <!--spring security -->
    <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>

</web-app>

项目结构

在此处输入图像描述

从索引页面我重定向到登录页面,同时在控制器中我实例化一个 bean(POJO/Model)以在下一页进一步使用。成功登录用户进入欢迎页面。

编辑: Index.jsp:

<c:redirect url="login"/> 

仅包含一个自动重定向。

我已经在 stackoverflow 中搜索了以前的解决方案,但没有解决我的问题。

任何帮助是极大的赞赏。

4

0 回答 0