Webwork learning notes

zhaozj2021-02-11  205

webwork study notes ------------------------------ Author: kingfish (vc - @ sohu.com) Keywords: webwork1. 4, Tomcat5 -------------------------------------- I have learned Webwork recently, found that the information is very small. (If you have, please send me a copy, thank you), because it is an open source project, just look at the source code. The following is a note that I have finished, it is relatively simple, I hope to give it. Netizens bring a little help.

Well level, inevitable, please forgive point!

Environmental Description: Use Tomcat5.0 Webwork1.4 to open WebWork.war in Tomcat's WebApps in Tomcat's WebApps in Tomcat.

I. A servlet: Webwork.dispatcher.Servletdispatcher 1. Introduction WebWork1.4 All self-contained examples are submitted to this servlet for processing, the importance is of course self-evident. Open Webwork / Web-INF Web.xml, You can see the following configuration

... action webwork.dispatcher.servletdispatcher 1 ... action *. action ... 2 function: 1. Process the Action request 2. Find the corresponding Action class, generate an instance. 3. Execute the DOVALIDATION () check input parameter; 4. If the result is legal, doexecute (); 5. Depending on the execution result string (" Success "," INPUT "," ERROR "" Find Views Configuration Go to the corresponding view.

II. Write a simple example

HelloAction.java source code

Import web.action.Actionsupport; import webwork.action.action;

Public class helloaction extends actionsupport {private string name; public helloAdition () {}

Public void setname (String name) {this.name = name;}

Public string getname () {return this.name;

Public void Dovalidation () {else if (name == null || name.length () <1) {adderror ("name", "can't be null or empty!");}}

// If you don't do other processing, you can not Override this method. By default returns Success public string doexecute () {return success;}} The compiled Class file is copied into WebWork / Web-INF / CLASSES. 2. Configure Two configuration methods Optional: (1) Configure views.properties (under WebWork / Web-INF / CLASSES) Hello.Artion = helloActionHello.input = helloinput.jsphello.success = hellosuccess.jsphello.rror = HelloError.jsp

(2) Configuring Actions.XML (under WebWork / Web-INF / CLASSES) Added an action HelloSuccess.jsp HelloError.jsp Helloinput.jsp

3. Related JSP files Establish the following four JSP files, store the directory: Webwork. (1) Index.jsp Test Webwork </ title> </ head> <body> <a href = "Helloinput.jsp"> Example </a> </ body> </ html> (2) Helloinput.jsp <html> <head> <title> test webwork </ title> </ head> <body> <form Action = "hello.action" method = "post"> <input type = "text" name = "name" value = "" /> <input type = "submit" value = "submit" /> </ form> < /BODY> (/HTML> (3 )Hellosuccess.jsp (3 )HTML> (h), itletete "/title) ,/head>, brodyhemianhello world! </ body> </ html> (4) HelloError. JSP is the same, change the string. This example is just in the configuration, and the running process does not use this page.</p> <p>4. Run (1) Start Tomcat (2) IE Enter: http: // localhost: 8080 / webwork / index.jsp (3) Do not enter any characters, submit, the page is still submitted after the Helloinput.jsp inputs characters, page Go to Hellosuccess.jsp</p> <p>5. Process Description (1) After starting Tomcat, initialize servletdispatcher (2) in the input page (Helloinput.jsp), enter the character submission (submit to the hello.action) (3) Configure it in Web.xml, this request Procedure by servletdispather. (4) Servlet finds configuration (Configuration content: hello.action = helloaction) (5) in accordance with ActionName ("Hello") (5) Generate HelloAction Instance (6) Servlet calls helloaction Dovalidation () check Input parameters. (7 Verification pass, servlet calls HelloAction's doexecute (), return success ("Success"). (8) Find: hello.suk (actionaliasname.view = PageName) (9) Servlet in FORWARD To HelloSuccess.jsp (10) output Hello World!, Complete. If you do not enter a direct submission, the following steps have different steps (7) checks, resulting in error messages. Other methods are detected, the error message is returned by default. " INPUT "(8) Find: hello.input = helloinput.jsp (9) Servlet FORWARD to Helloinput.jsp (10) is completed.</p> <p>6. Supplement HelloAction The steps are actually: servletdispatcher-> genericDispatcher-> call executection () -> ActionSupport's execute () -> Call HelloAction's corresponding method. 5 In order to be simply described, this is described. If you These are interested in seeing servletdispatcher, genericdispatcher, actionsupport, action, etc.</p> <p>III. Webwork comes with an example of Bank App 1. Environment http: // localhost: 8080 / Webwork's Bank App Related Class: WebApps / WebWork / Web-INF / LIB / WebWork-Examples.jar .examples.bank.transfer related JSP: WebApps / WebWork / Examples / Bank / INDEX.JSP, Transfer.jsp, Confirm.jsp related configuration: WebApps / WebWork / -Web-INF / CLASS / Views.properties # Bank Example (Struts example adaptation) bank.transfer.action = bank.Transfer (i.e. webwork.examples.bank.Transfer) bank.transfer.input = transfer.jsp bank.transfer.success = confirm.jsp bank.transfer.error = transfer.jsp since WebWork.Properties is equipped with web.action.packages = web.examples, web.examples.vxml, thus configured Bank.Transfer.Action = Bank.Transfer omitted WebWork.examples.</p> <p>2.index.jsp <jsp: Forward page = "Bank.Transfer! Default.Action" /> fairly and <form action = "Bank.Transfer! Default.Action" method = "post"> <input type = "submit" /> </ Form> Auto Submit. (1) Submit to Servlet, servlet Processing Bank.Transfer! DEFAULT.Action (constitutes: ActionaliasName ! CommandName .action) Due to Command in Action (Command is: Default), lookup DOCOMMand via Reflect That is, DodeFault () is executed to return "INPUT" (2) INPUT corresponding to Transfer.jsp, go to this page. (3) After entering the parameters, execute bank.transfer.action, other processes and above The second part is the 5th knot similar. ============================================ ================================================ Kingfish 2004.3 If the transfer, please keep the document complete.</p> <p>Welcome to exchange!</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5949.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="5949" 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.039</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 = 'dQW_2BTrO7jFVhrU3DVHUV6i9Z1m2TDu7aUSqbT_2Ftt89utQ_2FDxiX3RSqCK4r00Sf2iQnaJI33CqNnWZYhI'; 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>