웹 워 크 에서 action result type

 Webwork1.x  ,Webwork2 Action    , Result     Result Type,   Result Type                    ,    com.opensymphony.xwork.Result  。Result Type  Action               !        ,     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>
       location parse    ,location  action        ,parse     location  OGNL     。
 
  1) dispatcher
    action    ,        View,Webwork2      RequestDispatcher    ,    Request/Response       , Request  Atrributes    ,      redirect    。
 
  2) redirect
                    ,redirect         Request,  Request          ,      requet.getAtrribute     set   ,     action   ,errors,field errors ,  Action    Single-thread model  。

  3) chain
    action ,   View    ,  action          action。       actionName,          action  。 :
    <result name="success" type="chain">
        <param name="actionName">bar</param>
        <param name="namespace">/foo</param>
    </result>
            action:
    <action name="bar" class="myPackage.barAction">
        ...
    </action>

  4) velocity
  5) freemarker
  6) jasperreports
  7) xslt
                   View。

          Result Type   ,     Action testSendmail,               email。     Result Type,  Result  。
   
    com.mycompany.webwork.example.SendmailResult
           :from ,to, subject,       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">[email protected]</param>
        <param name="to">[email protected]</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   Email    
    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;
    }
  }

         Action:
  package com.opensymphony.webwork.example;
 
  import com.opensymphony.xwork.ActionSupport;

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

    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,    ,     :

sending mail....
      To:[email protected]
    From:[email protected]
  Subject:hello,webwork 

좋은 웹페이지 즐겨찾기