1. Integrate with Struts after login:
① Test 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 ";
}
2 applicationContex-security.xml Configuration:
<Http auto-Config = 'true' access-denied-page = "/deny. jsp"> (custom access denial page)
<Form-login Login-page = "/login. jsp"
Authentication-failure-url = "/login. jsp? Error = true"
Always-use-default-target = "true" default-target-url = "/user. Action"/> (jump to action after login)
③ Login. jsp:
<Form
Action = "$ {pagecontext. Request. contextpath}/j_spring_security_check" (fixed)
Method = "Post" style = "width: 260px; text-align: center;">
<Fieldset>
<Legend>
Login
</Legend>
User:
<Input type = "text" name = "j_username" style = "width: 150px ;"
Value = "$ {sessionscope ['spring _ security_last_username ']}"/>
<Br/>
Password:
<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>
④ Configure the struts interceptor in Web. xml: (404 error caused by missing configuration)
<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>
2. Engineering: