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 WebWork Learning

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to achieve WebWork learning, the content is concise and easy to understand, absolutely can make your eyes shine, through the detailed introduction of this article I hope you can gain something.

WebWork Learning Step 1: A servlet :webwork.dispatcher.ServletDispatcher

1. profile

All actions in webwork1.4 included examples are submitted to this servlet for processing, and the importance is self-evident.

Open webwork\WEB-INF under web.xml, you can see the following configuration

... action webwork.dispatcher.ServletDispatcher 1 ... action *.action ...

2 Functions: 1. Handling action requests

2. Find the corresponding action class and generate an instance.

3. Execute doValidation() to verify the input parameters;

4. If the result of 3 check is legal, execute doExecute();

5. According to the execution result string ("success","input","error") find views configuration go to the corresponding view.

WebWork Learning Step 2: Write a Simple Example

1. HelloAction.java Source Code

import webwork.action.ActionSupport; import webwork.action.Action; public class HelloAction extends ActionSupport { private String name ; public HelloAction() { } public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void doValidation() { else if(name==null||name.length() helloerror.jspview> helloinput.jspview> action>

3. Related jsp files

Create the following four jsp files, storage directory for:webwork.

(1)index.jsp

test webwork example

(2)hellosuccess.jsp

test webwork

(3)hellosuccess.jsp

Test Hello world!

(4)helloerror.jsp

Idem, change the string can be. This page is only used in configuration in this example.

4. run

(1)start Tomcat

(2)IE The requested URL/webwork/index.jsp was not found on this server.

(3)Do not enter any characters, submit, the page remains at helloinput.jsp

Enter characters and submit, the page goes to hellosuccess.jsp

5. process description

(1)After starting Tomcat, initialize servlet(ServletDispatcher)

(2)On the input page (helloinput.jsp), enter the character commit (commit to hello.action)

(3)According to the configuration in web.xml, this request is handled by ServletDispather.

(4)servlet looks up configuration by actionName("hello")(configuration content:hello.action=HelloAction)

(5)Creating HelloAction instances

(6)The servlet calls HelloAction's doValidation() to verify the input parameters.

(7)If the check passes, the servlet calls HelloAction's doExecute() and returns success ("success").

(8)According to the views configuration found:

hello.success=hellosuccess.jsp (actionaliasName.viewName=pagename)

(9)forward to hellosuccess.jsp in servlet

(10)output hello world!, complete.

If you don't enter it directly, the following steps are slightly different.

(7)Check failed, error message generated. Error message detected in other methods, default returns "input"

(8)Hello.input=helloinput.jsp

(9)forward to helloinput.jsp in servlet

(10)complete.

6. The steps to add HelloAction are actually:

ServletDispatcher->GenericDispatcher->

invoke executeaction()-> execute() of ActionSupport->

Call the corresponding method of HelloAction.

The description in 5 is described for simplicity only.

If you are interested in these, you can check out ServletDispatcher,GenericDispatcher,ActionSupport,Action etc.

WebWork learning step 3: webwork comes with examples Bank app simple introduction

1. environment

Bank app under JSP in http://localhost:8080/webwork

Related classes:webapps\webwork\WEB-INF\lib\webwork-examples.jar webwork.examples.bank. Transfe

Related jsp: webapps\webwork\examples\bank\index.jsp,transfer.jsp,confirm.jsp

Related configuration: webapps\webwork\-WEB-INF\classes\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

Because webwork.properties comes with

webwork.action.packages=webwork.examples, webwork.examples.vxml

So the above configuration bank.transfer.action=bank.Transfer omits webwork.examples.

2.index.jsp

equivalent to

WebWork Learning Step 4: AutoSubmit.

(1)Submit to servlet, servlet handle bank.transfer! default.action(Compose:actionAliasName+! commandName+.action)

Because there is command in action (command is:default), search doCommand by reflect, that is,(doDefault),

doDefault() returns "input"

(2) The view corresponding to input is transfer.jsp, go to this page.

(3)Enter the parameters and submit, execute bank.transfer.action, and the rest of the process is similar to Section 2, Section 5 above.

The above is how to realize WebWork learning. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to 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