Build a Struts Framework
Create a project
[File]-[new]-[web project]
In the displayed dialog box, name the project and click Finish]
Create a project> right-click the project and choose myeclipse> Add struts capabilities and select struts1.2> finish.
Enter basic information and click Finish]
As shown in figure
Create a JSP Interface
Login. jsp Interface
<% @ Page Language = "Java" pageencoding = "UTF-8" %> <% string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML>
Web. xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </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>
Struts-config.xml
<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype Struts-config public "-// Apache Software Foundation // DTD struts configuration 1.2 // en" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <Struts-config> <action-mappings> <! -- Type attribute: The specific struts request class, that is, the User-Defined Servlet Path attribute: the value in the action in the form, that is, the Request Path scope attribute: Request range parameter attribute: method Name of the specific request --> <! -- Controller description --> <action Path = "/loginaction" type = "com. itlwc. Action. loginaction" Scope = "request"> <! -- Configure the jump page --> <forward name = "success" Path = "/success. JSP "> </forward> <forward name =" unsuccess "Path ="/unsuccess. JSP "> </forward> </Action-mappings> <! -- Resource file --> <message-resources parameter = "com. itlwc. Struts. applicationresources"/> </Struts-config>
Loginaction. Java
Create a package and name it com. itlwc. Action.
Create a class file under the package: loginaction. Java
Package COM. itlwc. action; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import Org. apache. struts. action. action; import Org. apache. struts. action. actionform; import Org. apache. struts. action. actionforward; import Org. apache. struts. action. actionmapping; public class loginaction extends action {// The configuration information in the struts-config.xml file is loaded in the actionmapping object // actionforward class: encapsulated the servlet jump command @ override public actionforward execute (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception {string username = request. getparameter ("username"); string Password = request. getparameter ("password"); If ("LWC ". equals (username) & "123 ". equals (password) Return Mapping. findforward ("success"); else return mapping. findforward ("unsuccess ");}}
Success. jsp
<% @ Page Language = "Java" pageencoding = "UTF-8" %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML>
Unsuccess. jsp
<% @ Page Language = "Java" pageencoding = "UTF-8" %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML>