Example of Webwork2 and Springframework Integration (Original) (3-1)

xiaoxiao2021-03-06  85

3, use the webwork2 to implement the web representation layer

(1) Change the servlet controller: WW2 / web-inf / web.xml

Org.springframework.web.context.contextloaderListener

com.atlassian.xwork.ext.resolverSetupServletContextListener

Webwork

com.opensymphony.Webwork.dispatcher.servletdispatcher

velocity

com.opensymphony.webwork.views.Velocity.WebWorkVelocityServlet

1

Webwork

*. action

velocity

*. VM

Index.jsp

404

/ error.jsp

Webwork

/Web-inf/webwork.tld

l Use WebWork2's servletdispatcher to control all requests and map to * .Actionl In order to use Velocity, you should add the WebWorkVelocityServlet controller and map to * .vm

l In order to use the webwork2 tag in JSP, you need to define the webwork2 tag library; and copy the web.tld to the WW2 / Web-INF directory.

(2) Creating a controller: SpringAppaction

Package web;

Import java.util.list;

Import org.apache.commons.logging.log;

Import org.apache.commons.logging.logfactory;

Import Bus.ProductManager;

Import com.opensymphony.xwork.actionsupport;

Public class springappaction extends actionsupport {

/ ** Logger for this class and subclasses * /

Protected final log logger = logfactory.getlog (getclass ());

Private productManager product;

PRIVATE STRING NOW;

PRIVATE LIST PRODUCTS;

Public String Execute () throws exception {

Now = (new java.util.date ()). TOSTRING ();

Logger.info ("Returning Hello View with" Now);

Products = prodman.getProducts ();

RETURN SUCCESS;

}

Public productManager getProdman () {

Return Prodman

}

Public void setProdman (ProductManager Productman) {

This.Prodman = product;

}

Public String getnow () {

Return now;

}

Public void setnow {

THIS.NOW = NOW;

}

Public List getProducts () {

Return Products;

}

Public void setProducts (List product) {

THIS.PRODUCTS = Products;

}

}

l This uses SpringAppAction to implement the same functionality as SpringAppController

l SpringAppAction Extension ActionSupport (this is the default implementation of the Action interface) and overrides the execute () method

l execute () method is the execution logical unit of Action, and the specified view page is displayed by returns the return flag through Return.

l There are some of the following returns to use:

Ø SUCCESS: Action is successful, display result view

Ø None: Action is successful, no need to display the view

Ø Error: Action failed, display error view

Ø INPUT: Need more input to make the action success; a typical example is a form processing, when the user enters invalid, re-display the form view Ø login: The user does not log in to act, display login view

l Webwork2 does not have the MODEL mechanism for Spring MVC Framework, but use its properties to save Model data, and you can get data through these properties in the result view.

转载请注明原文地址:https://www.9cbs.com/read-122831.html

New Post(0)