Webwork2 learning notes (1)

zhaozj2021-02-16  61

Recently I plan to start learning Webwork, here I want to take this blog to record my learning history, I hope to make an exchange with all the webwork enthusiasts.

Not much nonsense, I will introduce my preparation for this study:

1. Tools and Environment Preparing JDK1.4.2 (% java_home%) Eclipse3.0 (recommended plugin: lomboz, xmlbuddy, tomcatplugin) WebWork2.1 (% webwork_home%) Tomcat5.0.25

2. Learning information Preparing the tutorial of Webwork2.1 (under WebWork2.1 / DOC)

The following is starting.

[First WebWork Program HelloWorld's Construction]

1. . Eclipse with a new Tomcat Project, where I built a project called Z_Webwork Tomcat Project directory structure Z_Webwork follows: Z_Webwork / work Z_Webwork / WEB-INF Z_Webwork / WEB-INF / classes Z_Webwork / WEB-INF / lib Z_Webwork / WEB-INF / SRC

2. Import% webwork_home% / webwork-2.1.jar to z_WebWork / Web-INF / LIB COPY% WebWork_HOME% / lib / core / *. Jar to z_webwork / web-inf / lib

3. Setting the Eclipse environment variable right-click on the project z_WebWork-> Properties-> java build path-> add library-> user library -> new user-defined library: webwork_lib -> add jars% webwork_home% / web-2.1.jar -> Add Jars% WebWork_Home% / lib / core / *. Jar

4. Establishing three basic profiles (1) Web.xml location in Webwork: z_webwork / web-inf / content is as follows:

My WebWork Application Webwork com.opensymphony.webwork.dispatcher.servletdispatcher 1 Webwork *. Action < / url-pattern> Webwork /web-inf/lib/webwork-2.1.jar < / Tagl Man (/web-app> (2 )XWork.xml location: z_webwork / web-inf / src / content is as follows:

(3) Validators.xml location: z_webwork / web-inf / src / content is as follows:

< validator name = "expression" class = "com.opensymphony.xwork.validator.validators.ExpressionValidator" />

Ok, such a webwork's skeleton is well, the overall structure is as follows:

5. Here we will be in accordance Lesson 3: Actions and Results do an example ex01-index.jsp: This page is a form submitted to an action (HelloWebWorldAction) processing HelloWebWorldAction.java: inherited ActionSupport realized HelloWebWorldAction, here HelloWebWorldAction play in MVC Control ex01 -success.jsp: HelloWorldAction After successful, you will return this page here, in order to facilitate management, I am using the tutorial to build directory LESSON03 / EXAMPLE01 in Z_WebWork, and puts EX01-INDEX.JSP and EX01-SUCCESS.JSP below it The HelloWebWorldAction.java location is Z_WebWork / Web-INF / SRC / Lesson03, in the subsequent notes, all of the examples I will store the code in this structure, respectively, respectively:

//ex01-index.jsp

Webwork tutorial - Lesson 3 - Example 1 </ Title> </ head></p> <p><body></p> <p><p> Click The Button Below To Activate HelloWorldAction. </ P></p> <p><form action = "hellowebworld.action" method = "post"> <p> <input type = "submit" value = "Hello!" /> </ p> </ form></p> <p></ body> </ html></p> <p>//HellowebWorldAction.java</p> <p>Package lesson03;</p> <p>/ ** * @Author Tailborn * * / import com.opensymphony.xwork.Actionsupport;</p> <p>Public class hellowebWorldAction Extends ActionSupport {String Hello;</p> <p>Public string getHello () {return hello;}</p> <p>Public String Execute () throws exception {hello = "hello, webworld!"; Return Success;}}</p> <p>//ex01-success.jsp</p> <p><% @ Taglib Uri = "Webwork" prefix = "ww"%> <html> <head> <title> Webwork tutorial - Lesson 3 - Example 1 </ title> </ head> <body></p> <p><ww: protoyal value = "hello" /></p> <p></ body> </ html></p> <p>6. Configure xwork.xml in <package name = "default" extends = "Webwork-default"></p> <p>And </ package></p> <p>The following codes are added to: <! - default-interceptor stack. -> <default-interceptor-ref name = "defaultstack" /> <! - action: Lesson 03: HelloWebWorldAction. -> <action name = HelloWorld "class =" lesson03.hellowebworldAction "> <resultment name =" success "type =" dispatcher "> eX01-success.jsp </ result> </ action> The modified xwork.xml is as follows: <? XML Version =" 1.0 "Encoding =" ISO-8859-1 "> <! Doctype xwork public" - // OpenSymphony Group // xw 1.0 // en "http://www.opensymphony.com/xwork/xwork-1.0.dtd "></p> <p><xWork> <! - "" "" "" "" "" "" "" "" "" "" "" "" "" "" "- = "Default" extends = "Webwork-default"> <! - default interceptor stack. -> <default-interceptor-ref name = "defaultstack" /> <! - action: Lesson 03: HelloWebWorldAction. -> <action name = "hellowebworld" class = "lesson03.hellowebWorldAction"> <result name = "success" type = "dispatcher"> eX01-success.jsp </ result> </ action> </ package> </ xwork></p> <p>7. At this point, the first WebWork example is built, start Tomcat, enter: http: // localhost: 8080 / z_webwork / lessost: 8080 / z_WebWork / Lesson03 / Example01 / EX01-index.jsp We will see as shown:</p> <p>Click the "Hello" button to appear page:</p> <p>[Example analysis]</p> <p>This is the first webwork program I made. I heard that Webwork was a simple and elegant MVC mode for the implementation framework than Struts, which didn't come.</p> <p>Configuration is simple: In the first example, the code that actually needs us only has part of the Action piece in xwork.xml.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-16762.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="16762" 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.049</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 = 'lbIJnJpt8PZnNL00NysgxH51k3nvXGiBbcYGjwZdCZnyEDwi624Kk1GDQymw8BzQt5TmoVd6GX2qVTgpvLJTBQ_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>