With WebWork, JSP, Velocity establish registration page (from: PConline Author: dodoMatix)

xiaoxiao2021-03-06  55

With WebWork, JSP, Velocity establish registration page Source: PConline Editor: chenyong [04-2-14 9:20] Author: dodo / Matix

Summary

WebWork is an open web application framework for simplifying web-based applications. This column describes the webwork and describes how to use WebWork and JavaServer Pages (JSP), Velocity to create a process of establishing registration interfaces.

The design and development of the web application is complex and take time. However, you can simplify the development process by using a framework to handle common web applications. Many open source web application frameworks can do this or even better. The best one in these development frames is WebWork, which is a web application development framework for the OpenSymphony group in the open source project.

The greatest advantage of Webwork is its simplicity and flexibility. Webwork has a small API that enables developers to develop work quickly. WebWork is a combination of many features and applicability, including using Variour View technology, such as JavaServer Pages (JSP), Velocity, Extensible Stylesheet Language Transformations Specification (XSLT), and JasperReporters. Webwork has an active community with many articles, developers and users.

Note: This article is based on WebWork1.3.0 Release Candidate 2 (RC2). In order to use the examples provided herein, you need to create a folder in your application server's webapps directory, copy the sample to your new folder, and copy the required JAR file to the web-inf / lib directory. . Download WebWork and source code related to this article here.

------ Actions

One of the most important features of Webwork is the action interface. WebWork Actions Controls the web application process by providing mapping between the page (view) and the business logic. In WebWork, submit the form to an action URI (Uniform Resource Identifier); this URI points to a corresponding action; action; the user can enter the corresponding view.

The following Class, LoginAction is an example of a web application-based registered form based on Web application. LoginAction extends ActionSupport. It is a base class that provides processing errors, view mapping, and many useful features.

Import Webwork.Action. *;

Public class loginaction extends actionsupport {private string username; private string password;

Public string getpassword () {return password;}

Public string getUsername () {return username;}

Public void setpassword (string password) {this.password = password;}

Public void setusername (string username) {this.username = usrname;}

Public string doexecute () {returnis Success;}

Public void Dovalidation () {if (username == null || username.length () <1) Adderror ("UserName", "please enter username."); if (password == null || Password.length () < 1) Adderror ("Password", "Please enter password.");}} LoginAction includes two JavaBeaN properties, Password and Username. WebWork places the data from the property into your view and automatically parses the parameters sent to the Action to set the attribute value.

LoginAction is overloaded two methods for ActionSupport: Dovalidation () and DoExecute (). Dovalidation () method verifies the parameters, and the doexecute () method allows the user to advance to the corresponding view. The doexecute () method returns a string, if all processing is successful, return constant access. If there is any problem, return constant input on the user input view. Calling Adderror in the loginaction pointing to an authentication issue and allows the user to return to the INPUT view.

---------

VIEW MAPPING Webwork has two ways from map to the view: via an action.xml file or a views.properties file. Each action should have an INPUT view and a Success view. The following Action.xml file defines two Actions, LoginJSP, and Loginvelocity. Both Actions use the LoginAction class. If LoginAction returns Success, the two Actions use the LoginAction class and turn the user to Success.html. If loginaction returns input, Action turns to the corresponding INPUT view, or login.jsp, or login.vm;

login.jsp success.html

login.vm success.html

-------- View Although webwork provides support for many different view technologies, the most common is JSP and Velociy. The following page is an example of two registration pages - one using the JSP another Velocity. Each page includes a user section and a password part, which is submitted to the WebWork Action. The Login.jsp page creates and processs the above two parts by using the WebWork tag library, and handles errors via the error collector. Webwork: TextField and Webwork: Password tag establishes a text and password section, and the Webwork: Iterator tag handles errors returned from loginaction. WebWork: Property tag Set the username, password, and errors properties.

<% @ Taglib Uri = "Webwork" prefix = "Webwork"%>

Webwork JSP Example </ Title> </ head></p> <p><body></p> <p><form action = "loginjsp.action" method = "post"></p> <p><WebWork: Property> <webwork: textfield label = "'name'" "name =" 'username' "/> <webwork: password label =" 'password' "name =" 'password' /> </ Webwork: Property ></p> <p><Input Type = "Submit" value = "submit" /> </ form></p> <p><WebWork: Iterator Value = "Errors" gt; <br> <webwork: proty /> </ webwork: iterator></p> <p></ body> </ html></p> <p>The login.vm page uses the Velocity template language to create a domain and handle an error. In velocity, the $ symbol indicates a reference. ! The symbol tells Velocity If the reference is empty, then nothing is not displayed. # 符 号 indicates an instruction. In the following example, $! Username and $! Password indicates that the reference is referenced to the username and password in the loginaction; #Foreach indicates a loop in the error handling property.</p> <p><html></p> <p><head> <title> Webwork velocity example </ title> </ head></p> <p><body></p> <p><form action = "loginvelocity.Action" method = "post"> <input type = "text" name = "usrname" value = "$! username" /> <input type = "text" name = "password" value = "$! password" /> <input type = "submit" value = "submit" /> </ form> #foreach ($ error in $ error) <br> $ error #end</p> <p></ body></p> <p></ html></p> <p>--------------- start working! Webwork is an easy-to-use, flexible, powerful open source web application framework, which presents its basic functions. Access to OpenSympony's website to learn and download the latest version of Webwork. After you download the Webwork, go to the upper part of Jakarta's website to find Velocity, a simple, fast open source engine, which is another choice for using JSP in the web page. ----------------- about the author</p> <p>Erik Swenson is an advisor and builder of Open Source Software Solutions. He mainly studies the use of open source software and components to develop Java. In addition, he participated in the development of open source project Jasperedit and OpenReports. ------------------ Resources</p> <p>Download this article related source code http://www.javaworld.com/javaworld/jw-03-2003/opensource/jw-0307-OpenSourceProfile.zip</p> <p>Download Web Web Site Download Webwork: http://www.opensymphony.com/webwork/</p> <p>Velocity is part of the Apache Jakarta project, downloaded from the following address: http://jakarta.apache.org/velocity/index.html</p> <p>"Using the Velocity Template Engine" GEIR MAGNUSSON JR. (JavaWorld, December 2001): http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html</p> <p>Other open source web application frameworks include:</p> <p>Maverick: http://mav.sourceforge.net/ struts: http://jakarta.apache.org/struts/index.html jasperreports homepage: http://jasperreports.sourceforge.net/</p> <p>Matrix authorized translation by JavaWorld. Join Matrix, dance with Java: www.matrix.org.cn</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-119133.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="119133" 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.038</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 = '_2B_2FUY9I8eruezBvAFHIY1_2FSTzqVc_2FNuN4XCX2uwmdHwBtHCHiD5631Rj5N3bLDZ5nEltCr4nXVQqjIpqi_2FOshBg_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>