springsecurity2学习笔记三(登陆后与struts结合、自定义访问拒绝页面)

一、登陆后与struts结合:

      ①测试action(user.action):

      public String execute() {
      Map session = ActionContext.getContext().getSession();
     
this.userName = (String) session.get("SPRING_SECURITY_LAST_USERNAME");
      System.out.println("userName:" + userName);
        return "success";
       }

 

      ②applicationContex-security.xml中配置:

      <http auto-config='true'  access-denied-page="/deny.jsp">(自定义访问拒绝页面)

      <form-login login-page="/login.jsp"
      authentication-failure-url="/login.jsp?error=true"
      always-use-default-target="true" default-target-url="/user.action" />(登陆后跳转到action)

  

      ③login.jsp中主要:

       <form
  
action="${pageContext.request.contextPath}/j_spring_security_check"   (固定的)
   method="post" style="width: 260px; text-align: center;">
   <fieldset>
    <legend>
     登陆
    </legend>
    用户:
    <input type="text" name="j_username" style="width: 150px;"
     value="${sessionScope['SPRING_SECURITY_LAST_USERNAME']}" />
    <br />
    密码:
    <input type="password" name="j_password" style="width: 150px;" />
    <br />

 

       deny.jsp中主要:    

     <body>
    <font size="5">Access Deny!</font><br>
    ${requestScope['SPRING_SECURITY_403_EXCEPTION'].message}
  </body>

 

     ④在web.xml中配置struts拦截器:(忘记配置了导致404错误)

     <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

 

 二、工程:

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值