WEB application using SNAP

zhaozj2021-02-16  35

WEB application using SNAP

Create a login page with Webwork, JSP, and Velocity

Overview

Webwork is an open source web application framework. The aim is to simplify web application development. This column introduces WebWork and explains the creation process of logging in to the web page using Webwork and two different view technology, JavaServerPages (JSP), and Velocity.

Web applications and development are complex and time consuming. However, you can use a framework to process a normal web application development task to simplify the process. Several Open Source The web application framework can do this and do more. The best one is Webwork, a web application framework for the OpenSymphony group from an open source project.

The biggest advantage of Webwork is its simple and flexible. Webwork has a small API. The API allows developers to start and run immediately. WebWork offers many properties and flexible integrated performance, including: using different view technologies such as JavaServerPages (JSP), Velocity, Scalable Single Language Conversion Description (XSLT), and JasperReports,

Note: This article is based on an alternative book 2 released by WebWork 1.3.0. In order to run the example, you need to create a folder in a webApps directory of your application server, copy the example into the new folder, and copy the required JAR file from the webwork distribution to the web-inf / lib directory. . Download Webwork and the source code required for this article from Resources.

Action

One of the most important features in Webwork is the Action interface. WebWork Action provides a map between page (or view) and corporate logic to control a web application. In WebWork, the form is submitted to an Action URI (the same resource tag); the URI is mapped to a corresponding action; performing the action; so that the user advances to the right view.

The next class, LoginAction is an example of the webwork action that handles the login form in a web-based application. LoginAction comes from extension ActionSupport, a base class that provides error handling, view mapping, and many other 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 Contains two JavaBeaN properties, Password, and username. WebWork will remove data from these properties, put the data you need into your view; and you can automatically explain any parameters to set the attribute value in the action.

LoginAction uses two functions from ActionSupport: DOVALIDATION () and DoExecute (). Dovalidation () function verifies the legality of the parameters and drives the user forward to the appropriate view by the doexecute () function. The doexecute () function returns a string. If the string is a constant success, the string is a constant input, which is sent back to the INPUT view, and the Dovalidation () function call in the loginaction Adderror indicates an illegal parameter problem and returns the user to the INPUT view.

View mapping

WebWork ACION maps to the view with two methods: via an action.xml file or a views.properties file. Each ACION should have an INPUT view and a Success view. The next Action.xml file defines two Actions: LoginJSP and Loginvelocity. Both actions use the LoginAction class. If loginaction returns Success, take the user to Success.html. If loginaction returns INPUT, the action is moving to the corresponding INPUT view, which is either login.jsp, or login.vm:

login.jsp success.html login.vm success.html View

WebWork provides support for many different view technologies, the most common to make JSP and Velocity. The following page is two login page examples - one created with JSP and creates it with Velocity. Each page contains a form with a username and password field submitted to a WebWork action.

Login.JSP Pages use the WebWork tag library, create and iterate two fields and repeat iterations by collecting errors. Webwork: TextField and Webwork: Password tag creates text and cryptographic fields, and Webwork: Iterator tag repeats any errors returned from loginAction. Webwork: Property tag set UserName, Password, and Erroors 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: iterator value = "errors"> <br> <webwork: proty /> <webwork: iperator> </ Body> </ html></p> <p>Login.vm Pages use the Velocity temporary language to increase the domain and iterate all errors. In Velocity, the $ symbol represents a reference;! The symbol tells Velocity If the reference is empty, nothing is displayed; # symbol represents an instruction. In the next example, $! UserName and $! Password Access LoginAction's UserName and Password Attributes; # foreach directive loops through the Erroors 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 = "name =" password "value =" $! password "/> <input type = "Submit" value = "submit" /> </ form> #foreach ($ error in $ errors) <br> ire #end </ body> </ html></p> <p>take action now</p> <p>Webwork is a simple, flexible, powerful open source web application framework. This article describes the basic WebWork function. Access the OpenSympony site for more instructions and download the updated Webwork version. When you are finished, go to the Jakarta site to see a look at Velocity, a simple, fast open source temporary engine, which is an alternative to JSP in your web page.</p> <p>About author</p> <p>Erik Swenson is an advano and founder of Open Source Software Solutions. He is proficient to develop Java using open source software and components, and he has developed Jasperedit and OpenReports open source project.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-27234.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="27234" 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.050</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 = '4DtFrHK2js_2BQTQC_2FU_2BI_2BFb26htZhG68_2BmCabPGDkj10pbgdNClnFWrUi8AejKdN65_2BSthl7NokYXuJw1pRYQtQ_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>