1. <i id='mz2Jj'><tr id='mz2Jj'><dt id='mz2Jj'><q id='mz2Jj'><span id='mz2Jj'><b id='mz2Jj'><form id='mz2Jj'><ins id='mz2Jj'></ins><ul id='mz2Jj'></ul><sub id='mz2Jj'></sub></form><legend id='mz2Jj'></legend><bdo id='mz2Jj'><pre id='mz2Jj'><center id='mz2Jj'></center></pre></bdo></b><th id='mz2Jj'></th></span></q></dt></tr></i><div id='mz2Jj'><tfoot id='mz2Jj'></tfoot><dl id='mz2Jj'><fieldset id='mz2Jj'></fieldset></dl></div>
      <legend id='mz2Jj'><style id='mz2Jj'><dir id='mz2Jj'><q id='mz2Jj'></q></dir></style></legend>

        <tfoot id='mz2Jj'></tfoot>
      1. <small id='mz2Jj'></small><noframes id='mz2Jj'>

          <bdo id='mz2Jj'></bdo><ul id='mz2Jj'></ul>

      2. Struts2 - 如何将 JSP 页面的结果作为操作类中的字符串获取(用于电子邮件)

        Struts2 - How can I get the result of a JSP page as a string in an action class (for emails)(Struts2 - 如何将 JSP 页面的结果作为操作类中的字符串获取(用于电子邮件))
          <tbody id='f7w9P'></tbody>

          <small id='f7w9P'></small><noframes id='f7w9P'>

          <legend id='f7w9P'><style id='f7w9P'><dir id='f7w9P'><q id='f7w9P'></q></dir></style></legend>

                <bdo id='f7w9P'></bdo><ul id='f7w9P'></ul>
                <i id='f7w9P'><tr id='f7w9P'><dt id='f7w9P'><q id='f7w9P'><span id='f7w9P'><b id='f7w9P'><form id='f7w9P'><ins id='f7w9P'></ins><ul id='f7w9P'></ul><sub id='f7w9P'></sub></form><legend id='f7w9P'></legend><bdo id='f7w9P'><pre id='f7w9P'><center id='f7w9P'></center></pre></bdo></b><th id='f7w9P'></th></span></q></dt></tr></i><div id='f7w9P'><tfoot id='f7w9P'></tfoot><dl id='f7w9P'><fieldset id='f7w9P'></fieldset></dl></div>
                <tfoot id='f7w9P'></tfoot>
                  本文介绍了Struts2 - 如何将 JSP 页面的结果作为操作类中的字符串获取(用于电子邮件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想同时实现这两件事.

                  I want to achieve the 2 things at the same time.

                  我在 Struts2 中有一个常规的 jsp 页面.xx/yy/zz/email.jsp

                  I have a regular jsp page in Struts2. xx/yy/zz/email.jsp

                  <html>
                  <head>
                  </head>
                  <body>
                      <s:property value="email"/>
                  </body>
                  </html>
                  

                  这个页面的url可以是xx/yy/zz/myEmail.action,而一些action类会处理它...

                  The url of this page could be xx/yy/zz/myEmail.action, while some action class will handle it...

                  public class MyEmailAction {
                      private String email;
                      public String execute(){
                          this.email = 'abc@xyz.com''
                      }
                      //setter and getter for 'email'
                      ......
                  }
                  

                  现在,我想做另一个动作,将 xx/yy/zz/myEmail.action 页面的结果作为电子邮件发送.

                  Now, I would like to have another action, which sends the result of the page of xx/yy/zz/myEmail.action as email.

                  public class MyEmailAction {
                      private String email;
                      public String execute(){
                          this.email = 'abc@xyz.com''
                      }
                  
                      public String send() {
                          this.email = 'abc@xyz.com''
                          Map mapping;
                          //put this.email into the mapping
                          String result = getResultOfJSP('../../../xx/yy/zz/email.jsp', mapping);
                          Email.send('me@me.com', 'you@you.com', 'My Subject', result);
                      }
                      //setter and getter for 'email'
                      ......
                  }
                  

                  所以问题是:如何将渲染的 JSP 的结果作为字符串获取?

                  So the question is that: HOW CAN I GET THE RESULT OF A RENDERED JSP AS A STRING?

                  我想要这个的原因显然是我想在一个地方管理这个模板(email.jsp).

                  This reason why I want this is obviously that I want to manage this template in one place (email.jsp).

                  我知道我可以使用另一个速度 (vm) 页面,它与 jsp 具有完全相同的 html,但使用速度标记.但是每当我需要对这个模板进行更改时,我都必须在两个地方都这样做.

                  I know I could use another velocity (vm) page which has exact the same html as the jsp but with velocity markups instead. But then whenever I need to make a change to this template, I have to do it on both places.

                  我想我也可以使用 URL 来获取结果,但我不喜欢使用这种方式,因为它是对服务器的另一个请求.

                  I think I could also use URL to grab the result, but I prefer not to use this way as it's another request to the server.

                  谢谢

                  推荐答案

                  我在使用邮件 servlet 时遇到了这个问题,使用它来获取 jsp 的结果作为字符串:

                  I had this problem with using a mailing servlet use this to get the result of the jsp as a string:

                  HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) {
                  private final StringWriter sw = new StringWriter();
                  
                  @Override
                  public PrintWriter getWriter() throws IOException {
                      return new PrintWriter(sw);
                  }
                  
                  @Override
                  public String toString() {
                      return sw.toString();
                  }
                  };
                  request.getRequestDispatcher("email.jsp").include(request,
                      responseWrapper);
                  String result = responseWrapper.toString();
                  

                  设置邮箱给html内容:

                  Set the email to give html content:

                  Email.send('me@me.com', 'you@you.com', 'My Subject', result);
                  

                  这篇关于Struts2 - 如何将 JSP 页面的结果作为操作类中的字符串获取(用于电子邮件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                  <small id='sd34g'></small><noframes id='sd34g'>

                    <i id='sd34g'><tr id='sd34g'><dt id='sd34g'><q id='sd34g'><span id='sd34g'><b id='sd34g'><form id='sd34g'><ins id='sd34g'></ins><ul id='sd34g'></ul><sub id='sd34g'></sub></form><legend id='sd34g'></legend><bdo id='sd34g'><pre id='sd34g'><center id='sd34g'></center></pre></bdo></b><th id='sd34g'></th></span></q></dt></tr></i><div id='sd34g'><tfoot id='sd34g'></tfoot><dl id='sd34g'><fieldset id='sd34g'></fieldset></dl></div>

                      <legend id='sd34g'><style id='sd34g'><dir id='sd34g'><q id='sd34g'></q></dir></style></legend>
                      <tfoot id='sd34g'></tfoot>
                      • <bdo id='sd34g'></bdo><ul id='sd34g'></ul>
                            <tbody id='sd34g'></tbody>