简体   繁体   中英

Java servlet synchronize doGet inside doPost

I'm working on register's email confirmation.

Firstly, i creating random value from doPost() and sending this to final email as activation link:

int token = new Random().nextInt(999999-100000) + 100000;
sendMail mailAgent = new sendMail("Hello!", "Hello, Link: "+ request.getRequestURL().toString()+"?Sender="+nick+"&Token="+token);
mailAgent.to = "target@mail.com";
mailAgent.send();

...the message sent fine, but i have to get this value back as well.

The only idea how to - begin listen GET requests after mailAgent.send() method. It implies to freeze script's execution there.

I would to do something like this:

mailAgent.send();
doGet(request,response); 
// Will fire right after call, but i want to listen requests from here

Any suggestions?

If I understand correctly, you want to register the user once he has clicked on the link, containing a random token, sent in an email. The user might click on this link a long, long time after you have sent the mail. Your server might have rebooted, a lot of things might have happened.

So, store the random token in your database, along with the user ID, before sending it to the user by mail.

When the user reads the mail, clicks on the link and thus sends back the token, check that the token he has sent is the same as the one stored in database. If it is, then mark the user as registered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM