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

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

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

        在 Struts 2 中发送带有嵌入 URL 的邮件

        Sending mail with embedded URL in Struts 2(在 Struts 2 中发送带有嵌入 URL 的邮件)

        <small id='0SmnP'></small><noframes id='0SmnP'>

        <legend id='0SmnP'><style id='0SmnP'><dir id='0SmnP'><q id='0SmnP'></q></dir></style></legend>

          <bdo id='0SmnP'></bdo><ul id='0SmnP'></ul>

            <tbody id='0SmnP'></tbody>
          <tfoot id='0SmnP'></tfoot>

                • <i id='0SmnP'><tr id='0SmnP'><dt id='0SmnP'><q id='0SmnP'><span id='0SmnP'><b id='0SmnP'><form id='0SmnP'><ins id='0SmnP'></ins><ul id='0SmnP'></ul><sub id='0SmnP'></sub></form><legend id='0SmnP'></legend><bdo id='0SmnP'><pre id='0SmnP'><center id='0SmnP'></center></pre></bdo></b><th id='0SmnP'></th></span></q></dt></tr></i><div id='0SmnP'><tfoot id='0SmnP'></tfoot><dl id='0SmnP'><fieldset id='0SmnP'></fieldset></dl></div>
                  本文介绍了在 Struts 2 中发送带有嵌入 URL 的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我公司的项目,我必须发送包含嵌入式 URL 的电子邮件,系统会提示用户关注这些 URL.

                  For a project for my company, I have to send emails containing embedded URLs, which the user will be prompted to follow.

                  例如,一个人在网站上注册,然后 Struts2 应用程序会向该人发送一封电子邮件,其中有一个 URL 以确认订阅.

                  For example, a person registers on the website, and then the Struts2 application sends an email to that person in which there is a URL to confirm the subscription.

                  到目前为止,表单提交和发送电子邮件(从操作内部)都可以正常工作.我遇到的问题是我找不到生成要嵌入邮件正文的 URL 的方法.

                  So far, the form submission, and sending the email (from inside the action), work just fine. The problem on which I'm stuck is that I can't find a way to generate the URL I'd like to embed in the mail body.

                  我一定是做错了,但我在想类似以下的事情:

                  I must be doing it the wrong way, but I was thinking about something like what follows:

                  public String send() throws Exception {
                      StringBuffer body = new StringBuffer();
                  
                      HashMap<String, String> params = new HashMap<String, String>();
                      params.put("id", "xxxxxyyyyyaaaaa");
                  
                      body.append("Veuillez vous rendre ici :");
                      body.append(UrlManager.getUrlForAction("action", params));
                  
                      SendMail sendMail = new SendMail();
                      sendMail.send("me@me.fr", "Information", body.toString());
                  
                      return SUCCESS;
                  }
                  

                  其中会有一个 UrlManager(框架可以提供的东西)和一个方法 getUrlForAction(),它获取一个动作及其参数作为输入和输出一个包含相应 URL 的字符串(如 http://mysite.mycompany.com/confirm?id=xxxxxyyyyyaaaaa).

                  where there would be a UrlManager (something that could be made available by the framework) with a method getUrlForAction() that gets an action and its parameters as input and that outputs a String containing the corresponding URL (like http://mysite.mycompany.com/confirm?id=xxxxxyyyyyaaaaa).

                  有没有人对如何做到这一点有任何想法或指示?

                  Does anyone have any ideas or pointers on how to do that?

                  我尝试使用 UrlProvider,但在调用 determineActionUrl 时出现空指针异常.可能是我用错了.

                  I tried using UrlProvider, but I get a null pointer exception on the determineActionUrl call. Maybe I'm using it the wrong way.

                  HashMap<String,Object> params = new HashMap<String,Object>();
                  params.put("id", data.getMd5());
                  
                  UrlProvider up = new ComponentUrlProvider(
                                              new Component(ServletActionContext.getValueStack(ServletActionContext.getRequest())),
                                              ServletActionContext.getRequest().getParameterMap());
                  downloadUrl = up.determineActionURL("confirm", "/", "GET",
                                                      ServletActionContext.getRequest(),
                                                      ServletActionContext.getResponse(),
                                                      params,
                                                      "http", true, true, true, true);
                  

                  推荐答案

                  你需要在你的action中创建属性(依赖)

                  You need to create the properties (dependencies) in your action

                  @Inject
                  public void setActionMapper(ActionMapper actionMapper) {
                    this.actionMapper = actionMapper;
                  }
                  
                  private UrlHelper urlHelper;
                  
                  @Inject
                  public void setUrlHelper(UrlHelper urlHelper) {
                    this.urlHelper = urlHelper;
                  }
                  

                  然后在动作中你可以写类似的东西

                  then in the action you could write something like

                  Map<String, Object> parameters = new HashMap<>();
                  ActionMapping mapping = new ActionMapping("action", "namespace", "", parameters);
                  String uri = actionMapper.getUriFromActionMapping(mapping);
                  String url  = urlHelper.buildUrl(uri, ServletActionContext.getRequest(), ServletActionContext.getResponse(), parameters, "http", true, false, true, false);
                  

                  这篇关于在 Struts 2 中发送带有嵌入 URL 的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                • <legend id='F9L7w'><style id='F9L7w'><dir id='F9L7w'><q id='F9L7w'></q></dir></style></legend>
                    <tbody id='F9L7w'></tbody>

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

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