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:
4, compile, start the server:
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.
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.
6, start the server:
Click the Start Server button on the toolbar or select the menu "Run" - Start the server launch the server Jakarta-Tomcat server.
7, run:
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.
Through the above steps, the estimated target function is achieved.