how to call multiple actions in one request in struts2
I am using struts2.0.1, I want to get customer info and product info in one request and show them in one jsp, now I have CustomerAction.getCustomer and ProductAction.getProduct already,is there any way I can reuse these Actions and Methods, so I can combine them and show the returns in one jsp? Th开发者_JS百科anks
You should create a new action (or at least a new action method) and a new JSP. Fetching the products and customers should be handled by your model classes, so the action should be really simple and quick to create.
Use result type="chain"
to move from one action to another to a final jsp.You can also use result type="redirect"
but then you'll have to pass the parameters in the action mapping also like this
Here you can create two new action declaration in xml file. 1. For product 2. For customer
Chain product to customer
Create only one result page in customer (chained action)
In this result page you can include two jsp previously created.
You can use action chaining in which the chained action gets the complete value stack of previous action and thus the chained action's result page is the final page.
High re-usability can thus be achieved.
精彩评论