Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize HelloWorld through WebWork

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to achieve HelloWorld through WebWork", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve HelloWorld through WebWork" this article.

Assuming that the installation and deployment of Tomcat has been completed, open eclipse and create a new Tomcat project HelloWorld:

1. Download the WebWork package on the Internet and unzip it. Open the unzipped directory and you will see the following files and directories:

Webwork-2.x.jar is of course the Jar package released by WebWrok***.

Webwork-example.war is a representative functional demonstration example that comes with WebWrok. Mastering it is a shortcut to improve your WebWork technology.

Webwork-migration.jar provides class files for quick migration from version 1.x to version 2.x

Docs directory WebWrok usage documents, including api documents, clover documents, unit test (Junit) documents, etc.

All .jar packages used by the lib directory WebWork when running or compiling

Src directory source program directory

two。 To use WebWork, you need to put its runtime Jar package into the ClassPath that can be found by the Web container:

Put the webwork-2.x.jar described in step 1 into the WEB-INF\ lib directory under the Tomcat project. At the same time, all the jar files in..\ webwork-2.2.6\ lib\ default and the jar files starting with spring in..\ webwork-2.2.6\ lib\ spring are also placed in WEB-INF\ lib. These are all jar packages that are necessary to run WebWork.

The 3.Webwork framework provides a unified request entry through a JavaServlet controller, parses the requested url, and then invokes the corresponding Action for business processing. It is required to configure a dispatcher ServletDispatcher in the web.xml file, which initializes some configuration information of WebWrok, parses the Action configuration information of XWork, and assembles and invokes the corresponding interceptor (Interceptor), Action, Action Result (output of Action execution result) according to the request. The specific configuration is as follows:

…… Webworkservlet-name > com.opensymphony.webwork.dispatcher.ServletDispatcherservlet-class > servlet >. Webworkservlet-name > * .actionurl-pattern > servlet-mapping >.

In this way, all url requests at the end of .action will be directly dispatched by ServletDispatcher.

Let's use a classic HelloWorld example to verify the availability of the runtime environment and feel the development of a simple and powerful WebWork.

4. Import all the jar packages of WebWork just now, right click on the project, Build Path-Configure Build Path … Select Java Build Path in the pop-up dialog box, corresponding to the Libraries tab on the right, and select Add JARs. Button, select all the jar packages under the HelloWorld-WEB-INF-lib of the newly created project in the pop-up window, and click OK to exit. At this point, you will see some bottle-like jar under the project HelloWorld, which indicates that it has been successfully imported.

5. Under WEB-INF/src, create a Package with the name helloWorld, and another class with the name HelloWorldAction. Add the following code:

Package helloWorld; import com.opensymphony.xwork.*; public class HelloWorldAction implements Action {private String hello; public String execute () throws Exception {hello = "HelloWorld"; return SUCCESS;} public String getHello () {return hello;} public void setHello (String hello) {this.hello = hello;}}

HelloWorldAction is a common Java class that implements the interface Action. Action is a very simple interface with only one method: public String execute () throws Exception;. See the next section for an introduction to the Action class. HelloWorldAction has a String type field greeting. In the execute () method, greeting is assigned "HelloWorld!" and returns the string constant SUCCESS,SUCCESS. For more information on the definition of string constant, see the Action interface. This constant represents the successful execution of the execute () method and returns the success page.

6. Right-click the project name to create a new .jsp file-- the hello.jsp code is as follows:

> First WebWork Exampletitle > head > 00000000100001000010000100000011000010001110000000010000 test data

P > body >

7. Configure the web.xml file: create the web.xml file under WEB-INF, as follows:

Webworkservlet-name > com.opensymphony.webwork.dispatcher.ServletDispatcherservlet-class > servlet > webworkservlet-name > * .actionurl-pattern > servlet-mapping > webworkfilter-name > com.opensymphony.webwork.dispatcher.FilterDispatcherfilter-class > filter > org.springframework.web.context.ContextLoaderListenerlistener-class > listener > web-app >

8. Configure the xwork.xml file: create the xwork.xml file under WEB-INF/src, as follows:

"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"> hello.jspresult > action > package > xwork >

By using the command mode framework and interceptor framework of XWork, xwork.xml provides a command mode framework that supports Web functions and can quickly build Web applications. This is a standard statement.

To put it bluntly, it is to contact the files just now, which is used to transmit values.

9. Under the Tomcat installation directory..\ Tomcat 5.5\ conf, open the sever.xml file and add the following code:

Manager > Context > Host >

Modify the host file of the system and add the following code:

127.0.0.1 test

10. Open the browser and enter the URL: http://test/hello.action to see the following display:

00000000100001000010000100000011000010001110000000010000 test data Hello World

It shows that HelloWorld is successful through WebWork!

The above is all the content of the article "how to achieve HelloWorld through WebWork". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report