Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Struts Hibernate-spring Update Profile

Related Tutorials


 
 

Share on Google+Share on Google+

Update Profile

Advertisement
This page discusses - Update Profile

Update Profile

     

Update Profile

This facility is used for updating user information in the database. Such as login id, name, password, email address etc. When user wishes to change their information, he may proceed by clicking on Update Profile Menu, all the information is fetched from the database and set in the update form. then used can change their personal information.

In this section at first we see how the update form is developed after this we will discuss how to develop an action.

 

Developing an update form

 

At first import the struts specific tag libraries

<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>

Then make a form
<html:form action="/userregister" method="post" onsubmit="return validateForm(this);">
    User Id <html:text property="userid" size="30" maxlength="120" />
    Password <html:password property="password" size="30" maxlength="120" />
    Email <html:text property="email" size="30" maxlength="120" />
    Address <html:text property="address" size="30" maxlength="120" />
    Phone No <html:text property="phno" size="30" maxlength="120" />
  <html:submit>Save</html:submit>
</html:form>

Update Action

The Update action is responsible for setting value in the bean properties

It get the user id from the session and fetch all the information from the database of that user and sets into the bean properties file

HttpSession session = request.getSession();
	String id = (String) session.getAttribute("ID");
	roseindia.dao.hibernate.Login pojoObj = springHibernateDAO
		.loadUser(id);

	objForm.setId(pojoObj.getId());
	objForm.setUserid(pojoObj.getLoginid());
	objForm.setPassword(pojoObj.getPassword());
	objForm.setAddress(pojoObj.getAddress());
	objForm.setEmail(pojoObj.getEmail());
	objForm.setPhno(String.valueOf(pojoObj.getPhno()));
	forwardToPage = "input";

When user submits the form it saves all the values to the database as
roseindia.dao.hibernate.Login pojoObj = springHibernateDAO
		.loadUser(objForm.getId().toString());
	pojoObj.setLoginid(objForm.getUserid());
	pojoObj.setPassword(objForm.getPassword());
	pojoObj.setAddress(objForm.getAddress());
	pojoObj.setPhno(Integer.parseInt(objForm.getPhno()));
	pojoObj.setId(objForm.getId());
	pojoObj.setEmail(objForm.getEmail());
	springHibernateDAO.updateUser(pojoObj);
	forwardToPage = "updated";

A View of process is given below
 
Update Success
 
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: Update Profile  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
sakshi
September 19, 2011
php

please provide the same code for PHP as well... please.. its really urgent and i am stuck..
DMCA.com