【问题标题】:How to get data from activation link with Java Servlet如何使用 Java Servlet 从激活链接中获取数据
【发布时间】:2011-05-30 19:36:27
【问题描述】:

我正在使用 GWT,在用户注册之后,我需要向用户发送一封带有激活链接的邮件。

激活链接可能包含用户的用户名和哈希值。

使用 PHP,我知道使用 get 方法检索这些值。

我是新的 GWT Java,我希望能够获取激活链接中的值。我也在服务器上使用 Java。

我只是想知道,当用户在点击激活链接(其中包含一些用于识别用户的数据)后被重定向到我的网站时,我需要做什么。

【问题讨论】:

    标签: java email gwt servlets


    【解决方案1】:

    这与 GWT 无关。当用户单击激活链接时,将调用您的 servlet。例如,您有一个映射到/useractivate 的servlet,而您的URL 是http://yoursite.com/useractivate?hash=4342bc322&user=foo

    然后在你的servlet的doGet()方法中你需要调用:

    String hash = request.getParameter("hash");
    String user = request.getParameter("user");
    // .. handle activation
    

    【讨论】:

      【解决方案2】:

      您也可以在 GWT 中使用 RequestBuilder 调用 HTTP.GET 方法。看看RequestBuilder.GETits usage

      我觉得对你有帮助,建议你看看similar topic - making http request in GWT

      来自 GWT 教程:

      import com.google.gwt.http.client.*;
      ...
      
      String url = "http://www.myserver.com/getData?type=3";
      RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
      
          try {
            Request request = builder.sendRequest(null, new RequestCallback() {
              public void onError(Request request, Throwable exception) {
                 // Couldn't connect to server (could be timeout, SOP violation, etc.)
              }
      
              public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    // Process the response in response.getText()
                } else {
                  // Handle the error.  Can get the status text from response.getStatusText()
                }
              }
            });
          } catch (RequestException e) {
            // Couldn't connect to server
          }
      

      【讨论】:

        猜你喜欢
        • 2019-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多