Struts 1.1 installation
Installing Struts 1.1 is relatively simple. Suppose we use Tomcat 5.0, and installed under D: / Tomcat. First, please go to http://jakarta.apache.org/struts/ download struts 1.1, after decompression, you can see the Jakarta-Struts-1.1 directory, under this directory, you can see such a directory: WebApps. There are multiple * .war below the directory, our Copy Struts-Blank.war files Under D: / Tomcat / WebApps, RESTART TOMCAT, which generates a Struts-Blank blank Struts development environment under WebApps of Tomcat. In addition, Struts-Example.War in WebApps in your decompressed directory is a good struts learning tutorial, if you want to learn in-depth, please visit http://jakarta.apache.org/struts or download "Struts in action "E text.
2. A simple example
2.1 Logon.jsp
<% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
<% @ Page ContentType = "text / html; charset = GB2312"%>
<%
/ **
* This page shows logon interface.
* Title: Logon System
* Description: Logon Page
* Copyright: Copyright (c) 2004
* Company: www.Ewe.com.cn
* @Author bluesunny
* @version 1.0
* /
Response.setHeader ("Pragma", "NO-Cache");
Response.setHeader ("cache-control", "no-cache");
Response.SetDateHeader ("Expires", 0);
%>
hEAD>
Username:
Password:
html: form>
body>
html>
The page is logged into the page, applied to the html tab of the Struts.
2.2 Logonform.java
Package com.logon.app;
Import javax.servlet.http. *;
Import org.apache.struts.action. *;
/ **
* This page shows logonform.java * Title: Logon System
* Description: Logonform Page
* Copyright: Copyright (c) 2004
* Company: www.Ewe.com.cn
* @Author Bluesunny
* @version 1.0
* /
Public class logonform extends actionform {
PRIVATE STRING UserName;
PRIVATE STRING Password;
Public loginform () {
Username = NULL;
Password = NULL;
}
Public void setusername (String username) {
THIS.USERNAME = UserName;
}
Public string getUsername () {
Return this.username;
}
Public void setpassword (string password) {
this.password = password;
}
Public string getpassword () {
Return this.password;
}
Public void reset (actionMapping mapping, httpservletRequest request)
{
Username = NULL;
Password = NULL;
}
}
This page is an actionform bean, mainly to encapsulate client names and passwords.
2.3 LogonAction.java
Package com.logon.app;
Import java.io. *;
Import java.sql. *;
Import org.apache.struts.Action.action;
Import org.apache.struts.Action.actionForward;
Import org.apache.struts.action.actionmapping;
Import org.apache.struts.Action.actionform;
Import javax.servlet. *;
Import javax.servlet.http. *;
Import org.apache.struts.action. *;
/ **
* This page shows logonaction.java
* Title: Logon System
* Description: LogonAction Page
* Copyright: Copyright (c) 2004
* Company: www.Ewe.com.cn
* @Author Bluesunny
* @version 1.0
* /
Public class logonaction extends action {
Public ActionForward Execute (ActionMApping ActionMApping, Actionform Actionform,
HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESPONSE RESPONSE) THROWS EXCEPTION
{
LogonForm Form = (logonform) Actionform;
ActionerroS Errors = new actionerrors ();
String username = form.getusername ();
String password = form.getpassword ();
IF (UserName.equals ("Bluesunny" && password.equals ("bluesunny")) {Return ActionMapping.FindForward ("Success");
} else {
Errors.Add ("Login", New Actionerror ("Logon.Failed");
SaveerRors (Request, Errors);
Return ActionMapping.FindForward ("failed");
}
}
}
Take data in the ActionForm, proceed, and the result is returned to the JSP page.
2.4 Web.xml
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
init-param>
init-param>
init-param>
servlet>
servlet-maping>
welcome-file-list>
taglib>
taglib>
taglib>
taglib>
taglib>
web-app>
2.5 Struts-Config.xml
Xml Version = "1.0" encoding = "ISO-8859-1"?>
"- // Apache Software Foundation // DTD Struts Configuration 1.1 // en"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
form-beans>
Path = "/ logon" type = "com.logon.app.logonaction" name = "logonform" scope = "request" input = "logon.jsp"> action> 2.6 Application.properties Logon.failed = logon failed! Please logon in again! 2.7 Deploy Logon Application Create a success.jsp, enter: "SuccessFLLY!". Compile the source file, and deploy the application in Tomcat, assume that the deployment is below the app directory. We can boot browser access: http: // localhost: 8080 / app /. 2.8 directory structure / Web-infrest: / Web-INF / LIB: STRUTS.JAR / Web-inf / classes: / Web-inf / class / com / logon / app: * .class / Web-inf / classes / resources: * .properties 3. Summary This article explained in detail the installation method and raised a land example as the Struts framework. In addition, this paper also shows the Struts directory structure, which greatly reduces the burden of beginners, and should be used as Struts.