一、登陆后与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>
二、工程: