Webwork之action标签使用浅谈

webwork有这样一个标签,他可以去执行xwork用定义的action,然后把action返回的页面显示在调用这个标签的地方,从本质上说,action标签让你实现了前端控制器 

Action:

 

package  ch9;



import  javax.servlet.http.HttpServletRequest;

import  com.opensymphony.webwork.interceptor.ServletRequestAware;
import  com.opensymphony.xwork.ActionSupport;



public   class  TestActionTag  extends  ActionSupport  implements  ServletRequestAware  {
    HttpServletRequest request
=null;
    
public void setServletRequest(HttpServletRequest request) {
        
this.request=request;
        
    }

    
public String execute() throws Exception {
        request.setAttribute(
"test""test data");
       
for (int i = 0; i < 1000000; i++{
          System.out.println(i);
        }

        
return SUCCESS;
    }

   
}


TestActionTagResult.jsp(action的跳转页面,显示我们的内容)

 

<% @ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding
="GB18030"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% @ taglib uri="webwork" prefix="ww" %>
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:property  value ="#request.test" />
</ body >
</ html >


TestActionTag.jsp(我们使用action标签的页面,并没有显示内容)

executeResult="true"才会去执行action返回的result

<% @ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding
="GB18030"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
<% @ taglib uri="webwork" prefix="ww" %>
< meta  http-equiv ="Content-Type"  content ="text/html; charset=GB18030" >
< title > Insert title here </ title >
</ head >
< body >
< ww:action  name ="testActionTag"  executeResult ="true" />
</ body >
</ html >

 

xwork.xml

 

   < action  name ="testActionTag"  class ="ch9.TestActionTag" >
      
< result  name ="success" > /ch9/testActionTagResult.jsp </ result >
   
</ action >

 

运行结果TestActionTag.jsp,可以看到打印出了test data

 

后计:希望webwork能将此功能做成异步的,至于为什么,我想大家都清楚吧,这样,ajax就没什么市场了,呵呵

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值