Struts 1.1 installation, sample art

xiaoxiao2021-03-06  112

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);

%>

Logon </ Title></p> <p></ hEAD></p> <p><body></p> <p><html: errors /></p> <p><html: form action = "/ logon" FOCUS = "UserName"></p> <p>Username: <html: text property = "username" size = "25" /></p> <p>Password: <html: Password property = "password" size = "25" /></p> <p><html: Submit property = "submit" /></p> <p></ html: form></p> <p></ body></p> <p></ html></p> <p>The page is logged into the page, applied to the html tab of the Struts.</p> <p>2.2 Logonform.java</p> <p>Package com.logon.app;</p> <p>Import javax.servlet.http. *;</p> <p>Import org.apache.struts.action. *;</p> <p>/ **</p> <p>* This page shows logonform.java * Title: Logon System</p> <p>* Description: Logonform Page</p> <p>* Copyright: Copyright (c) 2004</p> <p>* Company: www.Ewe.com.cn</p> <p>* @Author Bluesunny</p> <p>* @version 1.0</p> <p>* /</p> <p>Public class logonform extends actionform {</p> <p>PRIVATE STRING UserName;</p> <p>PRIVATE STRING Password;</p> <p>Public loginform () {</p> <p>Username = NULL;</p> <p>Password = NULL;</p> <p>}</p> <p>Public void setusername (String username) {</p> <p>THIS.USERNAME = UserName;</p> <p>}</p> <p>Public string getUsername () {</p> <p>Return this.username;</p> <p>}</p> <p>Public void setpassword (string password) {</p> <p>this.password = password;</p> <p>}</p> <p>Public string getpassword () {</p> <p>Return this.password;</p> <p>}</p> <p>Public void reset (actionMapping mapping, httpservletRequest request)</p> <p>{</p> <p>Username = NULL;</p> <p>Password = NULL;</p> <p>}</p> <p>}</p> <p>This page is an actionform bean, mainly to encapsulate client names and passwords.</p> <p>2.3 LogonAction.java</p> <p>Package com.logon.app;</p> <p>Import java.io. *;</p> <p>Import java.sql. *;</p> <p>Import org.apache.struts.Action.action;</p> <p>Import org.apache.struts.Action.actionForward;</p> <p>Import org.apache.struts.action.actionmapping;</p> <p>Import org.apache.struts.Action.actionform;</p> <p>Import javax.servlet. *;</p> <p>Import javax.servlet.http. *;</p> <p>Import org.apache.struts.action. *;</p> <p>/ **</p> <p>* This page shows logonaction.java</p> <p>* Title: Logon System</p> <p>* Description: LogonAction Page</p> <p>* Copyright: Copyright (c) 2004</p> <p>* Company: www.Ewe.com.cn</p> <p>* @Author Bluesunny</p> <p>* @version 1.0</p> <p>* /</p> <p>Public class logonaction extends action {</p> <p>Public ActionForward Execute (ActionMApping ActionMApping, Actionform Actionform,</p> <p>HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESPONSE RESPONSE) THROWS EXCEPTION</p> <p>{</p> <p>LogonForm Form = (logonform) Actionform;</p> <p>ActionerroS Errors = new actionerrors ();</p> <p>String username = form.getusername ();</p> <p>String password = form.getpassword ();</p> <p>IF (UserName.equals ("Bluesunny" && password.equals ("bluesunny")) {Return ActionMapping.FindForward ("Success");</p> <p>} else {</p> <p>Errors.Add ("Login", New Actionerror ("Logon.Failed");</p> <p>SaveerRors (Request, Errors);</p> <p>Return ActionMapping.FindForward ("failed");</p> <p>}</p> <p>}</p> <p>}</p> <p>Take data in the ActionForm, proceed, and the result is returned to the JSP page.</p> <p>2.4 Web.xml</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! DocType web-app</p> <p>Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"</p> <p>"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"></p> <p><web-app></p> <p><Display-Name> Struts Logon Application </ Display-Name></p> <p><! - Standard Action Servlet Configuration (With Debugging) -></p> <p><servlet></p> <p><servlet-name> Action </ servlet-name></p> <p><servlet-class> org.apache.struts.Action.ActionServlet </ servlet-class></p> <p><init-param></p> <p><param-name> config </ param-name></p> <p><param-value> /web-inf/struts-config.xml </ param-value></p> <p></ init-param></p> <p><init-param></p> <p><param-name> debug </ param-name></p> <p><param-value> 2 </ param-value></p> <p></ init-param></p> <p><init-param></p> <p><param-name> detail </ param-name></p> <p><param-value> 2 </ param-value></p> <p></ init-param></p> <p><Load-on-Startup> 2 </ loading-on-startup></p> <p></ servlet></p> <p><! - standard action servlet mapping -></p> <p><servlet-mapping></p> <p><servlet-name> Action </ servlet-name></p> <p><url-pattern> *. do </ url-pattern></p> <p></ servlet-maping></p> <p><! - the welcome file list -></p> <p><Welcome-file-list></p> <p><Welcome-File> Logon.jsp </ welcome-file></p> <p></ welcome-file-list></p> <p><! - Struts Tag Library Descriptor -> <taglib></p> <p><taglib-uri> / tags / struts-bean </ taglib-uri></p> <p><taglib-location> /web-inf/struts-bean.tld </ taglib-location></p> <p></ taglib></p> <p><taglib></p> <p><taglib-uri> / tags / struts-html </ taglib-uri></p> <p><taglib-location> /web-inf/struts-html.tld </ taglib-location></p> <p></ taglib></p> <p><taglib></p> <p><taglib-uri> / tags / struts-logic </ taglib-uri></p> <p><taglib-location> /web-inf/struts-logic.tld </ taglib-location></p> <p></ taglib></p> <p><taglib></p> <p><taglib-uri> / tags / struts-nested </ taglib-uri></p> <p><taglib-location> /web-inf/struts-nested.tld </ taglib-location></p> <p></ taglib></p> <p><taglib></p> <p><taglib-uri> / tags / struts-tiles </ taglib-uri></p> <p><taglib-location> /web-inf/struts-tiles.tld </ taglib-location></p> <p></ taglib></p> <p></ web-app></p> <p>2.5 Struts-Config.xml</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! DocType struts-config public</p> <p>"- // Apache Software Foundation // DTD Struts Configuration 1.1 // en"</p> <p>"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"></p> <p><struts-config></p> <p><form-beneans></p> <p><form-bean name = "logonform" type = "com.logon.app.loginform" /></p> <p></ form-beans></p> <p><action-mappings></p> <p><action</p> <p>Path = "/ logon" type = "com.logon.app.logonaction" name = "logonform" scope = "request" input = "logon.jsp"></p> <p><forward name = "success" path = "/ success.jsp" /></p> <p><forward name = "failure" Path = "/ logon.jsp" /></p> <p></ action></p> <p><message-resources parameter = "resources.Application" /> </ struts-config></p> <p>2.6 Application.properties</p> <p>Logon.failed = logon failed! Please logon in again!</p> <p>2.7 Deploy Logon Application</p> <p>Create a success.jsp, enter: "SuccessFLLY!".</p> <p>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 /.</p> <p>2.8 directory structure</p> <p>/ Web-infrest:</p> <p>/ Web-INF / LIB: STRUTS.JAR</p> <p>/ Web-inf / classes:</p> <p>/ Web-inf / class / com / logon / app: * .class</p> <p>/ Web-inf / classes / resources: * .properties</p> <p>3. Summary</p> <p>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.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-125459.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="125459" 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.052</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 = 'JysBa5LLSk6SSGiRfmx3_2FiVUt8tB3BABNxCZOE7USfaqQq0mUiNJ2nmx65BcD9kuxBxLENnlhZbvwDdyaF8x9A_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>