Foreword: For many times, I have always been online to see the article written by others, "stealing" people's labor results, my heart is a bit awkward. Write this article to commemorate my college life in the school that will leave your beloved school! At the same time, I also hope that I will work well in the future!
1. The origin of Struts Struts is an integral part of the Apache Jakarta project. The project's goal is to establish an open source framework provided by the establishment of a Java web application. At present, the version is generally used in 1.1, but it has also appeared 1.2. By using the Struts framework can improve and improve the application of Java Server Pages (JSPS), servlet, label libraries, and object-oriented technology in web applications. Applying the Struts framework to reduce the development time of your MVC (Model-View -Controller) design mode, thereby increasing development efficiency.
2. Struts works in Struts, we have to mention the MVC design mode. MVC is an abbreviation of Model-View-Controller, which is a common design pattern in the web application. The MVC weakens the coupling between business logic interfaces and data interfaces, and makes view layers more varied. Struts is an implementation of MVC, which combines JSP, Java Servlet, Java Bean, Taglib and other technologies. Then let's take a look at the working principle of the Struts framework: Control: In Struts, ActionServlet plays a controller. ActionServlet is a universal control component. This control component provides an entry point that processes all HTTP requests sent to Struts. It intercepts and distributes these requests to the appropriate action classes (these action classes are subclasses of the Action class). Additional control components are also responsible for popping an action form (usually called frombean) with the corresponding request parameters, and transmits it to the action class (usually called ActionBean). Action class implements core business logic, which can access Java Beans or call EJB. All of these control logics use the struts-config.xml file to configure. View: Mainly by JSP to control the page output. It receives data in the Action Form, which utilizes HTML, Taglib, Bean, Logic. Model: In Struts, there are mainly three beans, namely: action, actionform, ejb, or java bean. Actionform is used to encapsulate customer request information, and the Action acquires data in the ActionForm, and then processes the EJB or Java Bean.
3 Struts Advantages and Disadvantages Advantages: 1. TAGLIBs provided by Struts can greatly save time. 2. Performance is separated from logic. 3. It is more convenient to maintain and expansion. 4 Easy to develop shortcomings: a large number of labels, the difficulty of beginners is difficult.
4. Struts 1.1 Installation Install 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. 5. A simple example 5.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
5.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 ActionForm bean, it is mainly used to package the client's user name and password.
5.3 logonaction.java package com.logon.App; import java.io. *; import java.sql. *; Import org.apache.struts.Action.Apache.Struts.Action.Apacward; 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; ActionErrors errors = new ActionErrors (); String username = form.getUsername (); String password = form.getPassword (); Username.equals ("bluesunny" && password.equals ("bluesunny")) {return anctionsMapping.findforward ("Success") Else {Errors.Add ("Login", New Actionerror ("Logon.Failed"); SaveErRors (Request, Errors); Return ActionMapping.FindForward ("failed");}}} Get data in ActionForm, Processing, the processing result returns to the JSP page.
5.4 Web.xml XML Version = "1.0" Encoding = "ISO-8859-1">
/ taglib-uri>