spring security 登录页的问题?

我的登录页面登录成功之后不能是访问我的首页而是访问到了登录页面中的css:
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>用户登录</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK
href="images/style_sitemanage.css" type=text/css rel=stylesheet><LINK
href="images/login.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.6000.17080" name=GENERATOR></HEAD>
<BODY class=body_1>
<FORM id=loginForm name=loginForm action="${pageContext.request.contextPath}/j_spring_security_check"
method=post>
  <DIV id=login_z>
<DIV><span class="bt"><img src="images/beijin.png" width="407" height="45"></span></DIV>
<DIV id=login>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
    <TD height="30">用户名:</TD>
    <TD><INPUT id=loginName2 onfocus=this.focus() maxLength=30 size=22 name="j_username" style="width:170px"></TD>
    <TD></TD>
  </TR>
  <TR>
    <TD height="30">密&nbsp;&nbsp;码:</TD>
    <TD><INPUT id=loginPassword type=password maxLength=30 size=22
      name=j_password style="width:170px"></TD>
    <TD>&nbsp;</TD>
  </TR>
  </TBODY>
</TABLE></DIV>
<DIV id=login_2>
<input type="submit"  value="登录">
<input type="reset" value="重置">
&nbsp;&nbsp;&nbsp;</DIV></DIV></FORM>
<DIV id=footer></DIV>

</BODY></HTML>
---------
spring security

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"
default-autowire="byType" default-lazy-init="true">

<description>SpringSecurity安全配置</description>

<!-- http安全配置 -->
<s:http auto-config="true" access-decision-manager-ref="accessDecisionManager">
<s:intercept-url pattern="/login.jsp" filters="none"/>
<s:form-login login-page="/login.jsp"   default-target-url="/userAction!login.do"
authentication-failure-url="/login.jsp?error=true" />
<s:logout logout-success-url="/" invalidate-session="true"/>
<s:remember-me key="e37f4b31-0c45-11dd-bd0b-0800200c9a66" />
</s:http>

<!-- 认证配置 -->
<s:authentication-provider user-service-ref="userDetailsService">
<!-- 可设置hash使用sha1或md5散列密码后再存入数据库 -->
<!--  <s:password-encoder hash="plaintext" />-->
</s:authentication-provider>

<!-- 项目实现的用户查询服务 -->
<bean id="userDetailsService" class="com.dynastarter.sc.file.security.UserDetailsServiceImpl" />

<!-- 重新定义的FilterSecurityInterceptor,使用databaseDefinitionSource提供的url-授权关系定义 -->
<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<s:custom-filter before="FILTER_SECURITY_INTERCEPTOR" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionSource" ref="databaseDefinitionSource" />
</bean>

<!-- DefinitionSource工厂,使用resourceDetailsService提供的URL-授权关系. -->
<bean id="databaseDefinitionSource" class="org.springside.modules.security.springsecurity.DefinitionSourceFactoryBean">
<property name="resourceDetailsService" ref="resourceDetailsService" />
</bean>

<!-- 项目实现的URL-授权查询服务 -->
<bean id="resourceDetailsService" class="com.dynastarter.sc.file.security.ResourceDetailsServiceImpl" />

<!-- 授权判断配置, 将授权名称的默认前缀由ROLE_改为A_. -->
<bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased">
<property name="decisionVoters">
<list>
<bean class="org.springframework.security.vote.RoleVoter">
<property name="rolePrefix" value="ROLE_" />
</bean>
<bean class="org.springframework.security.vote.AuthenticatedVoter" />
</list>
</property>
</bean>
</beans>
------------------
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd">


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/applicationContext*.xml</param-value>
</context-param>

<!-- Filter 定义  -->
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<!-- Hibernate Open Session In View filter-->
<filter>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>

<!-- SpringSecurity filter-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>


<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>

<!-- Filter 映射 -->
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>hibernateOpenSessionInViewFilter</filter-name>
<url-pattern>/j_spring_security_check</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>document/documentManager.jsp</welcome-file>
</welcome-file-list>

<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--Spring的ApplicationContext 载入 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>




<!-- 出错页面定义 -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/common/500.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/common/500.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/common/404.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/common/403.jsp</location>
</error-page>


</web-app>
-------------------

暂时不知道原因 怀疑可能是过滤器过滤顺序的问题? 不知道谁有什么的好的解决方案 或者意见 留下你的意见....
---------------
根据我项目中的登录请求访问css或者图片,js的问题 。我在xml文件中重新配置了一下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"
default-autowire="byType" default-lazy-init="true">

<description>SpringSecurity安全配置</description>

<!-- http安全配置 -->
<s:http auto-config="true" >
<s:intercept-url pattern="/development-bundle/**" filters="none"/>
<s:intercept-url pattern="/document/css/**" filters="none" /> 
<s:intercept-url pattern="/document/img/**" filters="none" /> 
<s:intercept-url pattern="/document/iamges/**" filters="none" /> 
<s:intercept-url pattern="/document/js/**" filters="none" /> 
<s:intercept-url pattern="/images/**" filters="none" /> 
        <s:intercept-url pattern="/css/**" filters="none" /> 
        <s:intercept-url pattern="/js/**" filters="none" /> 
        <s:intercept-url pattern="/common/**" filters="none" /> 
<s:form-login login-page="/login.jsp"   default-target-url="/"
authentication-failure-url="/login.jsp?error=true" />
<s:logout logout-success-url="/login.jsp" invalidate-session="true"/>

</s:http>


<!-- 认证配置 -->
<s:authentication-provider user-service-ref="userDetailsService">
<!-- 可设置hash使用sha1或md5散列密码后再存入数据库 -->
<!--  <s:password-encoder hash="plaintext" />-->
</s:authentication-provider>

<!-- 项目实现的用户查询服务 -->
<bean id="userDetailsService" class="com.dynastarter.sc.file.security.UserDetailsServiceImpl" />

<!-- 重新定义的FilterSecurityInterceptor,使用databaseDefinitionSource提供的url-授权关系定义 -->
<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<s:custom-filter before="FILTER_SECURITY_INTERCEPTOR" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionSource" ref="databaseDefinitionSource" />
</bean>

<!-- DefinitionSource工厂,使用resourceDetailsService提供的URL-授权关系. -->
<bean id="databaseDefinitionSource" class="org.springside.modules.security.springsecurity.DefinitionSourceFactoryBean">
<property name="resourceDetailsService" ref="resourceDetailsService" />
</bean>

<!-- 项目实现的URL-授权查询服务 -->
<bean id="resourceDetailsService" class="com.dynastarter.sc.file.security.ResourceDetailsServiceImpl" />

<!-- 授权判断配置, 将授权名称的默认前缀由ROLE_改为A_. -->
<bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased">
<property name="decisionVoters">
<list>
<bean class="org.springframework.security.vote.RoleVoter">
<property name="rolePrefix" value="ROLE_" />
</bean>
<bean class="org.springframework.security.vote.AuthenticatedVoter" />
</list>
</property>
</bean>
</beans>
---问题得到解决不会出现登陆成功之后访问页面中的css,js,图片等问题..

你可能感兴趣的:(spring,jsp,Web,css,Security)