USING STRUTS TO Developur Web Application

xiaoxiao2021-03-06  93

Author: Holyfair CHENE-mail: plutocsj@hotmail.com

1. Introduction Struts is an open source of webservice Framework host by ASF as a part of its Jakarta project The primary architect and developer of the Struts framework is Craig R.McClanahan.He is also the primary architect of Tomcat 4. Notes:. 1 ) Struts is not only thread-safe but thread-dependent. 2) ActionForm beans minimize subclass code and shorten subclass hierarchies. 3) The Struts tag libraries provide general-purpose functionality. 4) The Struts components are reusable by the application. 5) The Struts localization strategies reduce the need for redundant JSPs. 6) Struts is designed an open architecture. 7) Struts is lightweight. 8) Struts is standards compliant with. 9) Struts is open source and well documented. 10) Struts is model neutral 2. Some Conception of Webserve 2.1 Servervet Servlet runs in the servlet container, which can be served by the servlet container dynamic loading control server. API: HTTPSERVLETREQUEST, HTTPSESSION and ServletContext provide methods of saving and reading shared data in Request, Session, and Application ranges, respectively. 2.2 JSP The JAVA program is added in traditional HTML, and the JSP tag constitutes a JSP page. The JSP container performs syntax analysis of a JSP file request and generates a Java Servlet source file, and then does not compile generation response.

2.3 Access scope and lifecycle of shared data Page -> Request -> session -> Application (scope gradually bigger, specific reference) 2.4 JavaBean meets a specific specification Java object to define some column properties and provide access And set these properties for public methods. (Specific reference: http: //java.sum.com/products/javabeans) 2.5 cookies cookies and url Rewriting Are Two Common Ways to Keep Track of Users Between Requests. Cookies Saved in Customers end. 2.6 CGI CGI uses standard operating system features, such as environment variables and standard input and output, to create a bridge, or gateway, between the web server and other applications on the host machine. The main drawback to CGI is that it must Run A New Copy Of The CGI-Aware Program for Each Request. 2.7 WEB Components Three Association * Request Forward * URL Redirection (REDIRECT) * Include 2.8 MVC (Model, View and Controller) Force Separate the application's input, processing, and output. Example: JSP (view), servlet (controller), JavaBean 3. Exploring the struts architecture As an open frame, Struts allows Technical construction outside the JSP . When considering improving the View technology in the Struts application, people first think of often use other servlet technology to replace JSP, such as XSLT or XSLT under servlet management. The figure below describes the case where JSP is applied in the Struts framework. View consists of JSP custom tag libraries and JSP pages, where the ActionForm class is a ValueObject object similar to JavaBean, with SET and GET methods for saving customers. According to the Struts's MVC concept, ActionForm is located between View and Controller's intermediate zone. Struts provides a set of complete dedicated tags to access data in Actionform from JSP.

2.1 Struts controller components [HyperLinks: ActionForward] To the application developer, a hyperlink is a path to some resource in the application in the configuration file, we can define a forward:. We can use mapping.forward (" Welcome ") in later Action. The Forward defined in the configuration file can be globally or is an Action of a proceedient [HTML Forms : Actionform] ActionForms Are Just JavaBeans with a couple of standard method Methods to manage the validation and revision cycle. It is responsible for transforming tables in HTML into an ActionForm data class and checks to servlet. We can customize an ActionForm as follows : public final class LogonForm extends ActionForm {private String username = null; public String getUsername () {return (this.username);} public void setUsername (String username) {this.username = username;}} Of course you have the struts This form is available in the configuration file to use it, such as: When an action is to use this form, here Add the name = "articleform" attribute in the configuration properties of the Action. [Custom Actions] An HTML Form Uses AN action parameter to tell the browser where to send the form's data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then . get the data it needs directly from the ActionForm bean Here's an example: public final class LogonAction extends Action {public ActionForward perform (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {myForm myForm = (myForm) form ;

// ... return mapping.findforward ("continue");}}} Action must also declare in Struts's configuration file. Such as: [actionmappings] in a Web Application, EVERY resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. to give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the mappings are usually defined in the XML configuration file: [ActionServlet] & [Localization] () 2.2 Struts Control Flow Chart clearly shows the Struts control process: Process analysis: Check the actionMApping instance that matches the user request, if not, return the user request path invalid information. If the ActionForm instance does not exist, create an actionform object, save the form data submitted to the Actionform. According to the configuration The information determines whether to perform form authentication. If you need to verify, call an actionform's validate () method. If the ActionForm's Validate method returns a NULL or returns a ActionError object that does not contain an actionMessage, it is successful. ActionServlet decisive Whether to forward the request to which action. If the corresponding Action instance does not exist, create this instance first, then call an action () method () method of the action () method returns an actionforward object, ActionServlet, send the customer request to the ActionForward object. The JSP component ActionForward object points to the JSP generates a dynamic web page, returns to the customer.

3. Configuring Struts Components Struts configuration files include the following: web.xml: The web application deployment descriptor required by the Java Servlet specification The servlet / JSP container uses this file to load and configure your application build.xml..: A file used by the Jakarta Ant build tool to compile and deploy your application Using Ant is not a requirement, but it is a popular choice among Struts developers struts-config.xml:.. The framework's deployment descriptor It is used to load and. configure various components used by the Struts framework. application.properties:This file provides the message resources for your Struts application. Like the build.xml file, it is not a strict requirement but is used by most Struts applications. 3.1 web.xml example Analysis: ------------------------------------------------ ----------------------------------- action org.apache.struts.Action.ActionServlet application Application < / param-value> config /web-inf/conf/struts-config.xml debug 2 <

/ init-param> detail 2 2 action *. do < / servlet-mapping> index.jsp / tags / struts-bean /web-inf/lib/struts-bean.tld / tags / struts-html /web-inf/lib/struts-html.tld / tags / struts-logic /web-inf/lib/struts-logic.tld --- -------------------------------------------------- ------------------------------- <1> Defined as a Web-App Configuration requirement. <2> Set an ActionServlet parameter (only Can load an ActionServlet parameter, otherwise Conflict) <3> Definition Struts Request. <4> Set Welcome File. It can only be the actual file, INDEX.DO form will not work. If you want to use a.do as home page, you can build an HTML contain Its, for example: ------------------------------------------- ------------------------------- struts demo </ title> <meta http-equiv = "refresh"</p> <p>Content = "0; URL = / cxdemo / login.do"> </ head> <body> </ body> </ html> -------------------- -------------------------------------------------- ------ <5> Set Taglib 3.2 struts-config.xml An example analysis: ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- <struts-config> <! - =========================================================================00 == -> <global-forwards> <forward name = "logoff" path = "/ logoff.do" /> </ global-forwards> <! - ======== Form bean definitions == ========================================== -> <form-beans> <form-bean name = "loginform" TYPE = "com.presentation.actionform.loginform" /> <! - ============================= ================ -> <action-mappings> <! - say hello! -> <action path = "/ login" type = "com.presentation.action .Loginaction "scope =" request "validate =" true "> <forward name = "Logon" path =</p> <p>"/Logon.do" /> </ action> </ action-mapings> <! - ========== Message resources definitions ================ ============ -> <message-resources null = "false" parameter = "ApplicationResources" /> <plug-in classname = "com.cappucinonet.strutscx.util.strutscxplugin"> < Set-property proty = "config" value = "/ web-inf / strutscx-config.xml" /> </ plug-in> </ struts-config></p> <p>-------------------------------------------------- -------------------------------------------- Also there is a global Exception, Controller, Data-Sources, etc. Not detailed. 3.3 Build.xml is based on ANT development based on the Struts project creation. Details can be found in the ANT manual. 4.installing the struts Core Files All The stock files That you need to run Struts are provided in the Struts library distribution. These include several JARs, the tag library descriptors, DTDs, and standard XML configuration files. This set of stock files, combined with the four files you provide, create a complete core Struts . configuration Here's the checklist: Download and unzip the Struts library distribution [ASF, Struts] Copy all the * .jar files to your application's / WEB-INF / lib folder Copy all the * .tld files to your / WEB-INF.. folder. Copy all the * .xml and * .dtd files to your / WEB-INF folder. Create your deployment descriptor (see 4.2). Create your Struts configuration file (see 4.4). Create your message resources bundle (see 4.5). Create your an T Build file (see 4.6). 5. Summary About Struts There are many aspects. Such as: 1) Struts Model Component 2) Struts Extension 3) Struts Internationalization 4) Validator Verification Frame 5) Complex abnormal processing 6) STRUTS Tag Library 7) Title Frame 8) LOG 10) StrutstestCase Test 11) Design mode 12) Struts All expansions are based on space here. Specific recommendations <Struts in action>, a good book.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-105873.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="105873" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.033</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'LU4nHG18oxgV6Mg_2BpZOCS8iX5QqLTxBHQbH0RU8VQHRTHT6ca9Y9HBhNzD9zMDRDgL_2FNUZsDk0UAwLt7SKsJ6g_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>