问题
I am using GWT and after that a user registers, I need to send the user a mail with an activation link.
The activation link might contain the username of the user and a hashed value.
With PHP, I know to retrieve these values using get method.
I am new GWT Java and I want to be able to get the values in the activation link. I am also using a Java on the server.
I just want to know, what i need to do when the user is redirected to my site after clicking on the activation link (which contains some data to identify the user).
回答1:
This has nothing to do with GWT. When the user clicks the activation link, a servlet of yours is invoked. For example, you have a servlet mapped to /useractivate, and your URL is http://yoursite.com/useractivate?hash=4342bc322&user=foo.
Then in the doGet() method of your servlet you need to call:
String hash = request.getParameter("hash");
String user = request.getParameter("user");
// .. handle activation
回答2:
You can also call HTTP.GET method in GWT with RequestBuilder. Have a look at RequestBuilder.GET and its usage
I think it will be helpful to you and I advise you to look at similar topic - making http request in GWT
From GWT tutorial :
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
}
来源:https://stackoverflow.com/questions/4533290/how-to-get-data-from-activation-link-with-java-servlet