How to achieve the simplest struts program

zhaozj2021-02-16  46

How to achieve the simplest struts program

[the goal]

Achieve the simplest Struts program. The program includes an input page and an output page, entering a page.

For learning programming, we have become accustomed to starting from Hello programs, practicing, this is the most effective way to get started. Let's design our first Struts program ---- Hello program. The goal of the Hello program is to implement a "Hello" word from an input box in an input JSP page, and the word "hello" is displayed in another output JSP page. According to the requirements of the Struts framework, this Hello program will contain an input JSP file, output a JSP file, an action file, formaction file, and configuration file. That is, this Hello program is a complete Struts program that can be running directly on the Tomact, Resin and other servers.

[effect]

Enter the page:

Output page:

[step]

1. Open the Visual Struts development environment:

(1) Copy the file to a directory of the local hard drive, for example

F: / javawebstudio /

(2) Run the javaWebstudio.exe file under the bin directory (simultaneously create a shortcut at the desktop, when starting, just click on the shortcut to the desktop), appears as follows:

In addition, the first time run JavaWebStudio will prompt whether to automatically configure environment variables, it is recommended to select automatic configuration.

2. Create an "empty Struts Ordinary Template" application:

Select the menu "File" - "New" - "New Project", pop up the new project dialog, as shown in Figure 3-1:

Select "Empty Struts Normal Template" in the dialog, enter "Simple", Package (Packet Name), and location (path path) in the project name, can be changed as needed. Finally, click the "OK" button to complete the establishment of the new project.

From the file manager, you can see that the file structure of the Simple project is as follows:

In the root of the SIMPLE project, you contain four subdirectories and two files, which is the standard structure of the JSPStudio project, it is best not to change their default names, otherwise there will be problems.

3. Use the Struts file wizard to establish new applications:

In the JSPStudio file manager, click the right mouse button. In the pop-up menu, select "Struts File Wizard" to enter the Struts File Wizard dialog, or select the menu "File" - "New" - "Struts File Wizard" into the Struts file wizard dialogue frame. As shown in Figure 3-3:

Enter the "Hellword" file name in the filename input field under the STRUTS file wizard dialog jsp file, other files use the default setting, click the "OK" button to complete the Struts file wizard.

Refresh the JSPSTUDIO file manager, then the two files are automatically generated in the web directory, which is hellword.jsp and hellword.jsp, the former is an input JSP file, the latter is output JSP file; SRC / EMPTYPRJ directory automatically generated Two files, are Hellword Action.java and Hellword Form.java, the former is an action file, the latter formaction file.

This example only uses a system default variable MyBeanVariable1, and it saves the input data.

4, project file structure

Config directory contains all profiles and Struts tag description files, such as web.xml, struts-config.xml, struts-bean.tld, struts-html.tld, struts-logic.tld, and struts-template.tld.tld Wait for files. LIB contains Struts library files and tape users such as Struts.jar, Struts-Legacy.jar, Commons-Lang.jar, and Xerces.jar.

The SRC directory contains Java original files and resource files, such as ApplicationResources.properties and ApplicationResources_ch.properties resource files, the former is an English resource file, which is a Chinese resource file. There is also a subdirectory "EmptyPRJ" in this directory, which is one from the package that is entered with the establishment project. There are two subdirectories "filters", "jdbc" in the EMPTYPRJ directory. The former is a filter directory. It is a Chinese solution. For details, please see the following relevant filter program design, Chinese solution chapter, the latter is a database connection pool file, Detailed analysis, please see the Struts Database Application Design Chapter of the Back.

The web directory contains the image files such as JSP, HTML and other web files and web files. This catalog is empty when new construction.

The build.xml file is compiled as the required profile. Since JSPSTUDIO is an ANT compiler, this file is essential in the jspstudio project, it is an ANT standard configuration file, all project directory structures are also Ant The compiler requires that the JSPStudio project is very compatibility with Ant, which is also one of the advantages of JSPSTUDIO.

Hello.prj files are project files, XML structures, as follows:

Simple

Struts

This is an empty Struts Ordinary Template </ Title></p> <p><package> EMPTYPRJ </ package></p> <p><typepath> / jave web project / empty struts common template </ typepath></p> <p><ProjectPath> f: / javawebstudio / javawebstudioWorkDir / Simple </ projectpath></p> <p><ProjectName> Tag is the project name; <ProjectType> Tag is the type of project, the content of this tag is best not to change; <title> The project is a brief instructions for the project, and can be filled in as needed; <package> tag is The default package name; <typepath> tag is the relative path of the project template; the <ProjectPath> tag is the absolute path saved by the project.</p> <p>4, compile, start the server:</p> <p>Click the Compile button on the toolbar or select the menu "Generate" - "Compile" Start Complication. The compilation process and the result is displayed in the output column.</p> <p>The output results indicate that the projects set by using ANT Compilation Build.xml have been successful. Copy the compilation result into the Tomcat server webapps directory and generate the package file Simple.war.</p> <p>6, start the server:</p> <p>Click the Start Server button on the toolbar or select the menu "Run" - Start the server launch the server Jakarta-Tomcat server.</p> <p>7, run:</p> <p>Expand the Web Directory under the File Manager SIMPLE project, see helloword.jap and hellowordout.jsp files, by double-clicking on the HelloWord.jap file, as shown. The edit window is divided into two parts, the upper part is the source program editing, the lower part is visual editing, similar to the Dreamweaver MX editing window. Click the Run button or selection menu on the toolbar or select "-" Run (Web Browse) "At this time, open the run results that Show HelloWord.JSP. Enter "Hello Word" in the input box in the Run Results page, click the "Submit" button, then forward the word "Hello Word" in the HelloWordOut.jsp file.</p> <p>Through the above steps, the estimated target function is achieved.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-25863.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="25863" 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.042</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 = 'CI_2FJAcmQJQ0Di_2FOipviwRh8q4LcLzoLq3Pb5gxqUHSNJ0RtLu8DQqGFX_2ByQxGVtdHTXmcozDcxm8BZn_2F'; 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>