ww.action标签在freemarker中的问题

本文探讨了Freemarker模板引擎与WebWork框架集成时出现的问题,特别是在Tomcat服务器下<@ww.action/>标签导致的显示异常及会话创建错误。文章还提供了可行的解决方案。

1.问题描述:
 在freemarker页面文件ftl中,使用<@ww.action name="test" executeResult="true" />显示xwork.xml中action为test返回result页面内容,
  <action name="test" class="org.TestAction">
   <result name="success" type="freemarker">
    /WEB-INF/hello.ftl
   </result>
  </action>
  
  <action name="test2" class="org.TestAction2">
   <result name="success" type="dispatcher">
    /hello.jsp
   </result>
  </action>
 如果为executeResult="false",表示不返回result页面.
 xwork.xml
  <action name="actionTagAction" class="org.ActionTagAction">

  </action>
 org.ActionTagAction action类
  private Map map = new HashMap();
 public String execute() throws Exception {
  ServletActionContext.getRequest().setAttribute("stringByAction", "This is a String put in by the action's doDefault()");
  map.put("01", "男");
  map.put("00", "女");
  return NONE;
 }

 public Map getMap() {
  return map;
 }
 public void setMap(Map map) {
  this.map = map;
 }
 ftl中使用action标签
 <@ww.action name="actionTagAction" executeResult="false" id="sexs"/>
 <@ww.property value="#attr.stringByAction" />
 <@ww.radio label="性别" name="sex" list="#sexs.map" value="'01'"/>
 

 <@ww.action />在使用jetty运行时,正常显示,但是使用tomcat时候,返回的result页面不能正常显示,报错:
 WebWork Problem Report
 WebWork has detected an unhandled exception:
 Messages: Cannot create a session after the response has been committed 
 --------------------------------------------------------------------------------
 Stacktraces
 java.lang.IllegalStateException: Cannot create a session after the response has been committed
报错的情况是首次请求包含<@ww.action />标签的页面,如果是先请求test,在请求包含<@ww.action />标签的页面是可以正常显示的.
经过测试发现:如果不返回result页面,而是得到test中的map或String变量值时,可以取到值,但是tomcat控制台同样也报出上面的错误,
解决方法: 在使用webwork中action标签时,在jsp页面中使用,返回的result页面不管是jsp或ftl都可以正常显示

(taglib.tld来源于:webwork-2.2.4.jar /META-INF/标签描叙符文件)
<%@taglib prefix="ww" uri="/WEB-INF/taglib.tld"%>
<ww:action namespace="/gl" name="test" executeResult="true" /><br/>
<ww:action namespace="/gl" name="test2" executeResult="true" />
/gl为xwork中的命名空间

webwork中标签在jsp页面中较完善,在freemarker中存在一些问题.

请分析下面代码:<#import "/decorators/includes/macros.ftl" as m> <#assign ww = JspTaglibs["/WEB-INF/webwork.tld"] /> <#include "/template/includes/actionerrors.ftl"> <#assign useStepNo=false> <#if requestForm.stepForms?exists> <#list requestForm.stepForms as stepForm> <#if stepForm.stepNo?exists> <#assign useStepNo=true> </#if> </#list> </#if> <script> document.onkeydown = function() { if(event.keyCode==116) { event.keyCode=0; event.returnValue = false; } if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 event.keyCode=0; event.returnValue=false; alert("Please do not exit like this again. This case maybe have some problem cause of the action.Please check it.\r\n 请下次不要再这样退出。由于你的这个动作,这个单子可能已经产生了错误,请检查。"); return false; } if ((event.ctrlKey)&&(event.keyCode==87)){ //屏蔽 Ctrl+n event.keyCode=0; event.returnValue=false; return false; } } //document.oncontextmenu = function() {event.returnValue = false;} function continueRuncard(){ var date = new Date(); var minute=date.getMinutes(); if(parseInt(minute)>=0 && parseInt(minute)<=5) { alert("整点系统同步中.\n请稍后再试!"); return false; } var compareResultComment=document.getElementById("compareResultComment"); if (compareResultComment!=null){ confineStringLength(compareResultComment,500); if(compareResultComment.value==""){ return false; } } var form = document.forms['']; form.action="continueRuncard.action"; form.submit(); } function cancelRuncard(){ var date = new Date(); var minute=date.getMinutes(); if(parseInt(minute)>=0 && parseInt(minute)<=5) { alert("整点系统同步中.\n请稍后再试!"); return false; } var form = document.forms['submitRequestFormForm']; form.action="cancelRuncard.action"; form.submit(); } function compareWithMes(){ <#if Rework> alert("Because RunCard's category is rework. \r\n System will not execute this function!"); return false; </#if> var form = document.forms['submitRequestFormForm']; if(!confirm("Do you want to create the comparison with MES document?\n你是否需要E-RC与MES做对比?\n\n确定 = E-RC对比MES(此动作可能需要花费几分钟时间,请耐心等待)\n\n取消 = E-RC不比对MES")){ return false; } form.action="eRuncardRule.action"; form.submit(); } function submitRunCard(){ var compareResultComment=document.getElementById("compareResultComment"); if (compareResultComment!=null){ confineStringLength(compareResultComment,500); if(compareResultComment.value==""){ return false; } } var date = new Date(); var minute=date.getMinutes(); if(parseInt(minute)>=0 && parseInt(minute)<=5) { alert("整点系统同步中.\n请稍后再试!"); return false; } disableButton(); var f=document.submitRequestFormForm; f.action = "submitRequestForm.action"; var xmlHttp = XmlHttp.create(); var async = false; xmlHttp.open("GET", "checkStepNoExistInFecp.action?lotId=${requestForm.lotId?if_exists}&holdStepNo=${requestForm.holdStepNo?if_exists}", async); xmlHttp.send(null); if(xmlHttp.responseText != null && xmlHttp.responseText == '<success/>'){ if (!confirm("你确认是否需要在这步做STR/MSTR and Link STR/MSTR \nNumber? If yes, 请确认E-runcard condition exactly \n match with FECP/STR, MSTR system\n\n确定 = 确认 Link STR/MSTR Number, submit E-runcard \n\n取消 = 修改 E-runcard")){ f.action = "viewUpdateRequestForm.action"; //f.submit(); } f.submit(); }else if(xmlHttp.responseXML != null && xmlHttp.responseXML.getElementsByTagName("success").length > 0){ if (!confirm("你确认是否需要在这步做STR/MSTR and Link STR/MSTR \nNumber? If yes, 请确认E-runcard condition exactly \n match with FECP/STR, MSTR system\n\n确定 = 确认 Link STR/MSTR Number, submit E-runcard \n\n取消 = 修改 E-runcard")){ f.action = "viewUpdateRequestForm.action"; //f.submit(); } f.submit(); }else{ f.submit(); } } </script> <@ww.form name="'submitRequestFormForm'" namespace="'/user'" validate="'true'" method="'post'" theme="'simple'"> <@ww.hidden name="'requestFormId'" value="${requestForm.id}"/> <@ww.token name="submitToken"/> <div class="app"> <h3>View e-Runcard Request Form</h3> <table border="0" cellspacing="1" cellpadding="8" width="100%"> <tr class="b"> <td>RunCard No.:</td> <td>${requestForm.caseNo?if_exists}</td> <td>Status:</td> <td><font color="red">${requestForm.status?if_exists}</font></td> </tr> <tr class="b"> <td>Applicant:</td> <td><@m.directoryLink requestForm.applicant?if_exists/> </td> <td>Organization:</td> <td>${requestForm.applicantOrg?if_exists}</td> </tr> <tr class="b"> <td>Submit Date:</td> <td>${requestForm.submitDate?if_exists}</td> <td>Effective Date:</td> <td>${requestForm.effectiveDate?if_exists}</td> </tr> <#include "viewIncludeLotInfo.ftl"/> <#include "viewIncludeSignInfo.ftl"/> <#include "viewIncludeErcHeaderInfo.ftl"/> <#include "viewIncludeErcCompleteInfo.ftl"/> <#switch requestForm.formType> <#case "Auto Reposition Step"> <#break> <#default> <table border="0" cellspacing="1" cellpadding="8" width="100%"> <tr> <th colspan="4">RunCard Steps Information</th> </tr> <#assign showWGAction = true > <#include "stepForm/includeStepForm.ftl"/> </table> </#switch> </table> <hr/> <#if requestForm.match?default("")=="N"> <table border="0" cellspacing="1" cellpadding="8" width="100%"> <tr class="b"> <td>Compare Result Comment <BR>请输入原因(Only 500 characters)</td> <td><@ww.textarea name="'requestForm.compareResultComment'" id="compareResultComment" cols="80" rows="5" theme="'simple'"/></td> </tr> </table> </#if> <table width="100%"> <tr> <td class="center"> <#if requestForm.formType="Normal"> <input type="button" onclick="compareWithMes()" value="Compare"/>     </#if> <#if requestForm.haveQtime?exists> <#if requestForm.haveQtime=="Y"> <#if requestForm.formType!="Scan Defect"> <#if requestForm.formType="Normal" && useStepNo && requestForm.match=="No Comparison" && !Rework> <input type="button" class="btn" value="Continue Runcard" onclick="alert('please compare runcard first.');"/>     <#else> <input type="button" class="btn" value="Continue Runcard" onclick="continueRuncard()"/>     </#if> </#if> <input type="button" class="btn" value="Cancel Runcard" onclick="cancelRuncard()"/>     </#if> <#else> <#if requestForm.formType="Normal" && useStepNo && requestForm.match=="No Comparison" && !Rework> <input type="button" class="btn" value="Submit" onclick="alert('please compare runcard first.');"/>     <#else> <input type="button" class="btn" value="Submit" onclick="submitRunCard()"/>     </#if> <input type="button" class="btn" value="Back" onclick="document.location.href='${req.contextPath}/user/viewUpdateRequestForm.action?requestFormId=${requestForm.id}'"/> </#if> </td> </tr> </table> <div> </@ww.form>
最新发布
09-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值