1. Download the struts jar package
2. Put the struts jar package in the WEB-INF/lib directory.
3. Configure struts-config.xml
| The code is as follows: |
Copy code |
|
<Form-beans>
<Form-bean name = "loginForm (named by yourself)" type = "com. struts. LoginActionForm (package and path of ActionForm)"/>
</Form-beans>
<Action-mappings>
<Action path = "/login (named by yourself )"
Type = "com. struts. LoginAction (package and path of Action )"
Name = "loginForm (must be the same as the name configured in <form-beans> )"
Scope = "request (request transfer method )"
>
<Forward name = "sucess" path = "/login_sucess.jsp"/> (successfully redirected to the page)
<Forward name = "failure" path = "/login_failure.jsp"/> (failed to jump to the page)
</Action>
</Action-mappings> |
4. Configure web. xml
| The code is as follows: |
Copy code |
|
<Web-app xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" version = "3.0" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<Display-name/>
<Servlet>
<Servlet-name> action </servlet-name>
<Servlet-class> org. apache. struts. action. ActionServlet </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-name> action </servlet-name>
<Url-pattern> *. do </url-pattern>
</Servlet-mapping>
<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
</Web-app> |