Establish a registration page with WebWork, JSP, Velocity

xiaoxiao2021-03-06  79

Establish a registration page with WebWork, JSP, Velocity

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 = userName;} public String doExecute () {return 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> <body> <form action = "loginjsp.action" method = "post"> <webwork: proty> <webwork: textfield label = "'name'" "name =" 'username' "/> <webwork: password label =" 'password' "" name = "'password'" /> < / WebWork: Property> <input type = "submit" value = "submit" /> </ form> <webwork: item value = "errors" gt; <br> <webwork: proty /> </ webwork: iperator> < / 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. <html> <head> <title> Webwork velocity example </ title> </ head> <body> <form action = "loginvelocity.action" method = "post"> <input type = "text" name = "username" Value = "$! username" /> <input type = "text" name = "password" value = "$! password" /> <input type = "submit" value = "submit" /> </ form> #foreach ($ Error In $ Errors) <br> $ error #end </ body> </ html></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-93535.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="93535" 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.034</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 = '8iLUuwoCQXEFkaTO_2FrCk0G119xtuokJaAJL01Wu3ssp6jNffq26xKs9U3qlrHRZsIFTggPk9eoWE7e5VLxMUrQ_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>