免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Webwork2之Action Result Type
Webwork2 之 Action Result Type

      和Webwork1.x不同,Webwork2的Action執(zhí)行完后,其Result對(duì)應(yīng)一個(gè) Result Type,而這個(gè)Result Type完全可以根據(jù)具體應(yīng)用或環(huán)境自己進(jìn)行 定義,只需實(shí)現(xiàn)com.opensymphony.xwork.Result接口。Result Type使得Action的執(zhí)行結(jié)果表現(xiàn)形式可以靈活多變!下面這會(huì)舉例說明,這里先看看Webwork2提供的幾種Result Type的定義,該定義在webwork-default.xml中,xwork.xml文件包含了該文件,自定義的Result Type可以直接寫在 xwork.xml中:
  <result-types>
    <result-type name="dispatcher" class="com.opensymphony.webwork.dispatcher.ServletDispatcherResult" default="true"/>
    <result-type name="redirect" class="com.opensymphony.webwork.dispatcher.ServletRedirectResult"/>
    <result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/>
    <result-type name="chain" class="com.opensymphony.xwork.ActionChainResult"/>
    <result-type name="xslt" class="com.opensymphony.webwork.views.xslt.XSLTResult"/>
    <result-type name="jasper" class="com.opensymphony.webwork.views.jasperreports.JasperReportsResult"/>
    <result-type name="freemarker" class="com.opensymphony.webwork.views.freemarker.FreemarkerResult"/>
  </result-types>
  其大多都有l(wèi)ocation和parse兩個(gè)參數(shù),location指明action執(zhí)行后接著去哪里,parse指明是否對(duì)location進(jìn)行OGNL表達(dá)式解析。
 
  1) dispatcher
    action執(zhí)行完后,請(qǐng)求會(huì)導(dǎo)向?qū)?yīng)的View,Webwork2幕后其實(shí)是用RequestDispatcher來處理的,所以原Request/Response對(duì)象會(huì)接著傳遞,原Request中的Atrributes不會(huì)丟失,這點(diǎn)與下面的redirect是不同的。
 
  2) redirect
    對(duì)上次的響應(yīng)將重定向到指定的位置,redirect是重新產(chǎn)生一個(gè)新的Request,原來Request保存的東西將不再有效,比如不能通過requet.getAtrribute 取得原來set的對(duì)象,也不能取得action的實(shí)例,errors,field errors等,因?yàn)锳ction是建立在Single-thread model上的。

  3) chain
    action鏈,特殊的View調(diào)用方式,一個(gè)action執(zhí)行完接著調(diào)用另一個(gè)action。有個(gè)必須的參數(shù)actionName,指明緊接著調(diào)用的另一action對(duì)象。如:
    <result name="success" type="chain">
        <param name="actionName">bar</param>
        <param name="namespace">/foo</param>
    </result>
  執(zhí)行后接著調(diào)用下面的action:
    <action name="bar" class="myPackage.barAction">
        ...
    </action>

  4) velocity
  5) freemarker
  6) jasperreports
  7) xslt
    以上都是用不同技術(shù)的產(chǎn)生不同的View。

  下面我舉個(gè)自定義Result Type的示例,假如我有個(gè)Action testSendmail,根據(jù)處理結(jié)果將給指用戶發(fā)送一份email。自定義一個(gè)Result Type,實(shí)現(xiàn)Result接口。
   
    com.mycompany.webwork.example.SendmailResult
    有三個(gè)必須參數(shù):from ,to, subject,一個(gè)可選參數(shù) body。
  在xwork.xml中定義如下:
  <result-types>
    <result-type name="sendmail" class="com.mycompany.webwork.example.SendmailResult"/>
  </result-types>
 
  action定義:
  <action name="testSendmail" class="com.mycompany.webwork.example.TestSendMailAction">
    <result name="success" type="sendmail">
        <param name="from">root@sina.com</param>
        <param name="to">user@sina.com</param>
        <param name="subject">hello,webwork!</param>
    </result>
    <result name="error" type="dispatcher">
        <param name="location">error.jsp</param>
    </result>
  </action>
 
  SendmailResult.java

  package com.opensymphony.webwork.example;

  import com.opensymphony.xwork.ActionInvocation;
  import com.opensymphony.xwork.Result;

  public class SendmailResult implements Result {
    private String to;
    private String from;
    private String subject;
    private String body;

    public void execute(ActionInvocation invocation) throws Exception {
    //TODO 實(shí)現(xiàn)Email發(fā)送部分
    System.out.println("sending mail....");
    System.out.println("   To:" + to);
    System.out.println("   From:" + from);
    System.out.println("Subject:" + subject);
    }

    public String getBody() {
    return body;
    }

    public void setBody(String body) {
    this.body = body;
    }

    public String getFrom() {
    return from;
    }

    public void setFrom(String from) {
    this.from = from;
    }

    public String getSubject() {
    return subject;
    }

    public void setSubject(String subject) {
    this.subject = subject;
    }

    public String getTo() {
    return to;
    }

    public void setTo(String to) {
    this.to = to;
    }
  }

  寫個(gè)簡(jiǎn)單的測(cè)試Action:
  package com.opensymphony.webwork.example;
 
  import com.opensymphony.xwork.ActionSupport;

  public class TestSendMailAction extends ActionSupport {
    public String execute() throws Exception {
      return SUCCESS;
    }
  }

  測(cè)試jsp,把它放在webwork-example/下:

  testsendmail.jsp

  <%@ taglib prefix="ww" uri="webwork" %>
  <html>
  <head><title>Test sendmail restul type</title></head>
  <body>
 
  <form action="testSendmail.action">
    <input type="Submit" value="Submit"/>
  </form>
  </body>
  </html>


  打開http://localhost:8080/webwork-example/testsendmail.jsp,提交頁面,控制臺(tái)輸出:

sending mail....
      To:user@sina.com
    From:root@sina.com
  Subject:hello,webwork

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
struts2學(xué)習(xí)筆記(9)——自定義攔截器
Struts2攔截器總結(jié)
xwork.xml中 組成Action配置的各個(gè)元素
webwork2 + spring 結(jié)合的幾種方法的小結(jié)
WebWork教程-0.90版
WebWork的強(qiáng)大的驗(yàn)證器
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服