有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

电子邮件如何通过Java Servlet从激活链接获取数据

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

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

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

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

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


共 (2) 个答案

  1. # 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. # 2 楼答案

    还可以使用RequestBuilder调用GWT中的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
        }