aspose file tools*
The moose likes Struts and the fly likes change password Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "change password" Watch "change password" New topic
Author

change password

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
hey i have an option on my web page of forget password & change passwod for that i need that on my action form my login name should be used as session but the problem is how can i use sessions please help me i dont know much aboout sessions

thank you
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
Hi Aditi,

Can you put some light on your requirement, and please add some code that you tried to implement this, that will help ranchers to come up with some solution for you.

Thanks,
Shailesh


Thanks,
Shailesh
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks Shailesh

actually i want that user can change their password if they forgot or if they want to change the password but without mentionaing loginname that loginname should be passed through the sessions now i want how to use sessions & at what place & in what manner

my userLogin.jsp page is



userloginaction


changepasswrod.jsp




changepasswordaction

Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
In userloginaction you can put userName in session(you can get session object from request which is parameter to execute method )if user id & password is validated.
Then in your changepasswrod.jsp you can retrieve it from session (In jsp we are having implicit session object).

HTH
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks for your reply but problem with me is how to do that

i dont kno how to use the sessions

thank you
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
can you help me in that

thank you
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
Hi Aditi,

you can get help of API for HttpServletRequest on this link.
(you can use getSession() method of HttpServletRequest object.)

for HttpSession you will get at this link.
(you can use getAttribute & setAtttibute method of session object.)
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks for your reply shailesh
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
one thing more i have tried

please have a look over it is it correct or not

if any modifications please let me know


in userloginaction.java
String username=userLoginForm.getUsername().trim();
HttpSession session=request.getSession(false);
session.setAttribute("user", "username");

in changepasswordaction.java

String user=session.getattribute("username");

one more thing ho wto invalidate it because when i have used it earlier
my whole application stop working

thank you
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

You probably need a type cast here, because return type of getAttribute is Object.



And you should store the value of username


Swastik
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thnks swastik for your reply

actually ihave used this only but by mistake written wrong

but this is still not working on my page
what should i do now
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

By not working on my page, what do you mean? What is happening or what is going wrong?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i have used this code on my userloginaction.java



now on changepasswordaction.java


i have made nothing on my changepasswd.jsp

now when i hve done this all & run my page then its goin towrads failure

help me
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Failure from userloginaction or changepasswordaction?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
actually when i click on changepassword link then jsp page open i can fill all the fields in changepassword.jsp
but as soon as i click on submit then it goes to failure

i think its due to i have not declared or used for session on my changepassword.jsp
please help me what should i do

thank you
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

I don't think you need to declare session in jsp, because action is being handled by the action handler class.
What is happening here?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
this is the correct changepassword action



i have updated it now here

now if any mistake then tell me
thank you
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Seems to be ok now, are you getting the correct output?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
output kahan se abhi to form run nhn kar rha hai i think i have done asimple mistake

can you do me afvour

i am posting here my userloginaction
please check it


changepasswordaction



if i have done a blunder then please ley me know

thank you o much
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Have you made any change in either of the two codes? And by the way you still have this problem



"user"?? it should be the variable name.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
yes swastik i still have the same problem



these lines are creatng session & then user is the variable with username as its value

in following code


i am getting my session in a new variable user to be used in my changepaswword.jsp page
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6





Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you for your reply swastik "user" taking null
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
Hi Aditi,

First of all go through getAttrubute() & setAttribute() method of HttpSession object.

in that setAttribute() first parameter is name of attribute and second parameter is object that you want to put in session.

above code will not work because you are setting string "username" in session with name as user.
So if you call you will get String object "username" in reply.

do setting attribute by following code,


and for getting from session





Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you so much shailesh it worked now i am getting no error now & my form is working at its best

thank you so much

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
but now one problem starts my form is not logging in
tell me one thing how to invalidate sessions

if you have any tutorials then let me know please
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
I would say again go through HttpSession methods there is one method to invalidate session.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you shailesh i have read your page link & also i have invalidate my session but still my form is not allowing me to login

can you please help me why is it so
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Not allowing me to login
, so what is exactly happening when you click submit?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
now when i click my submit button my page remains over there only it dont proceed to anywhere
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

What changes have you made in userloginaction? One more thing I could not figure out what has invalidate got to do with login? Invalidate is typically used when you no longer wish to hold the session, so a typical situation can be when the user logs out. Apart from this have you made any change in the login jsp page?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
yipeee my form worked automatically & it working fyn

thank you swastik & shailesh

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Great job. So it's done at last.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: change password
 
Similar Threads
How are sessions created in struts?
Cookies vs. Sessions .....Need an educated choice
page attribute tag for session?
Is it possible to merge two session?
Implementing password expiry using sessions