Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto generate link for newly registered user

 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner for web technology, developing one small web application.

How to generate a link to send to the user's mail, to use it to activate his/her account.

I have seen some links like: http://[Domain Name]/user/[user-id]/activate/[some 32 characters hash code]

please help..

 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Hope that helps.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ramnna, welcome to javaranch !

I can't give you the complete code but I can give you some hints. First of all in your database, there must be an additional column in the user table. The column will be a bit (or you can say boolean) column which will represent if the user's account is activated or not. When a user registers, his/her account will be deactivated (i.e. the column will have a value false or 0). You must also send an email to the user which should contain a link of this form

http://[Domain Name]/user/activate/[encrypted user-id]

You must also create a servlet which maps to /user/activate/* which will do the work of activating the user's account. When the user clicks on the link in the email, he/she will be taken to that servlet which will decrypt the user-id, set the activated column's value to true (or 1). After that the activation servlet must redirect the user to his/her home page...

(edit: added welcome message)
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both of you Ankit & Ryan for your kind help.

Ankit! I need to map this url(user/activate/*) in web.xml. Here my servlet class will use [encrypted user id], but how to get this encrypted code out of this link. Is there any way!


ref. link: http://[Domain Name]/user/activate/[encrypted user-id]

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the HttpServletRequest.getPathExtraInfo (or some such) method. It returns that part of the URL.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf its HttpServletRequest.getPathInfo() ...
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using this link: http://localhost:8080/AddressBook/something/12345678

Made changes in my web.xml:








Result: HTTP Status 404 - /AddressBook/something/12345678


please help...
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two problems with your code ramnna.

1. you have overridden doPost method and no doGet. So you can't access the servlet by entering a URL in the browser.

2. You have used System.out.println to output your message. This will not get sent to the browser. Instead usually this will go to the console of the servlet container.

A correct code would be

 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made some changes in my code & now it is done successfully ....

Thank you ... Ryan, Ankit, Ulf for your kind & prompt help.... thank you!


 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does doPost() really need to be implemented? You can just leave that away.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes! right Get is idempotent, means not supposed to change any thing on the server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic