This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Auto generate link for newly registered user Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Auto generate link for newly registered user" Watch "Auto generate link for newly registered user" New topic
Author

Auto generate link for newly registered user

ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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

Joined: Feb 22, 2009
Posts: 192



Hope that helps.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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)


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
Check out the HttpServletRequest.getPathExtraInfo (or some such) method. It returns that part of the URL.


Ping & DNS - my free Android networking tools app
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Ulf its HttpServletRequest.getPathInfo() ...
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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

Joined: Aug 03, 2008
Posts: 9291
    
  17

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

Joined: Mar 16, 2009
Posts: 129

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

Joined: Oct 08, 2006
Posts: 2458
Does doPost() really need to be implemented? You can just leave that away.
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

Yes! right Get is idempotent, means not supposed to change any thing on the server.
 
 
subject: Auto generate link for newly registered user
 
Similar Threads
Activate Account by clicking url in email
Generating unique Hash in Java
Activating account via java mail
opening ms outlook from java application
activate user account through email