充满创意的WebWork与Ajax结合使用的例子(没采用WebWork的方法)

WebWork提供的使用Ajax的配置及使用太麻烦了,又难以理解。所以本人自己写了一套很简单方法来访问:
1.Action代码:
        public String forwordLog(){
log.info("forword to log tab....");
return "forwordLog";
}
public String getLog(){
log.info("forword to getLog....");
String retDoc = "";
try{
if(fileName != null)
retDoc = FileUtil.readFileContent(fileName, displayRows);
}catch(Exception ex){
ex.printStackTrace();
}

inputStream = new ByteArrayInputStream(retDoc.getBytes());

return "getLog";
}
2.action.xwork.xml配置:
  <action name="config" class="com.bee.admin.config.action.SystemPropertiesAction">
      <result name="forwordLog" type="freemarker">/adminconfig/config/config_log_view.ftl</result>
      <result name="getLog" type="stream"></result>
  </action>
3.freemarker代码:
<script type="text/javascript" src="${base}/adminconfig/common/common.js"></script>
<script type="text/javascript">
<!--
function listLog(){
document.getElementById("msg").innerHTML = "";
var file = document.getElementById("T1").value;
var rows = document.getElementById("T2").value;
var url = "${commonUrl}/config.action?act=getLog&fileName="+file+"&displayRows="+rows;
var result = getHTMLContent(url, 'POST');
document.getElementById("log_zone").value = result;
}
//-->
</script>
注:1.getHTMLContent是common.js的ajax函数,直接返回结果;
    2.${commonUrl}是Action中获取的访问服务器的地址,如:http://192.168.21.30:8080/admin
    3.Action的xwork.xml中result配置和访问url中的act=getLog参数是经过包装的,你可以按一般的Webwork定义

没有任何的有关ajax的配置,跟一般webwork架构一样,比webwork的dwr简单多了。不明白的发邮件给我。

你可能感兴趣的:(freemarker,xml,Ajax,DWR,Webwork)