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



Home Answers Viewqa JSP-Servlet Updating user profile
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


praneeth
Updating user profile
2 Answer(s)      2 years and 3 months ago
Posted in : JSP-Servlet


how should i provide user to update his profile with edit option including entered data by user should be shown in jsp page fileds


Advertisement
View Answers

October 3, 2012 at 12:25 PM


The given code retrieve data from database and display in the html table. At each row, there is a button which consists of that particular id. When the user clicks the particular edit button, that data will get shown in another page and allow the user to update the record.

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><input type="button" name="edit" value="Edit" style="background-color:green;font-weight:bold;color:white;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>


October 3, 2012 at 12:25 PM


continue..

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>

3)update.jsp:

<%@page import="java.sql.*"%>
<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/application.jsp");
}
catch(Exception e){
System.out.println(e);
}
%>


Related Tutorials/Questions & Answers:
Updating user profile
Updating user profile  how should i provide user to update his profile with edit option including entered data by user should be shown in jsp page.... When the user clicks the particular edit button, that data will get shown
coding for updating profile
coding for updating profile  coding for updating profile
Advertisements
user profile - JSP-Servlet
user profile  how to create a user profile for each user in the database and enable the user to modify it using jsp
Update Profile
; The Update Profile page allows the logged in user to update his/her profile... or change his/her profile in the registration form, user has to click on the "... from database and displayed on the Updating Form. User can update the require
profile display
profile display  Is it possible to create a user profile in Servlet and JSP   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration
profile display
profile display  How to create a user profile in JSP   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
profile display
profile display  Create Jobseeker's profile in JSP and Servlet   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration-form-using
profile display
profile display  how to display matching jobs in jobseeker's profile using jsp-servlets?   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user
profile display
profile display  Search page to display matching results in JSP and Servlet   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml
profile page
profile page  sir, i am beginer in php i am creating simple web site.i am creating login form.the user login he can any status,photo update.he can display in home pages in all user login.but problem in user goto profile page
profile display
profile display  how to display matching Results using jsp-servlet?   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml http
profile display
profile display  Fetch Matching jobs in JSP Servlet  Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/jsp
update profile
update profile  coding for update profile
Update Profile
Update Profile       Update Profile This facility is used for updating user... user wishes to change their information, he may proceed by clicking on Update
Editing the Profile
Editing the Profile  how to populate drop-down menu instead of text box in editing the profile
profile display
profile display  JSP Servlet Search Page   1)search.jsp: <html> <head> </head> <body> <br><br><... also visit the following links: http://www.roseindia.net/jsp/user-search.shtml
coding for update profile
coding for update profile  coding for update profile
updating & deleting an employee
updating & deleting an employee  can anyone help out me please? advance thanks warm regards
Updating log4j programatically
Updating log4j programatically  Is there a ready made utility which I can use to edit the log4j.xml programmatically
profile doesn't match application identifier
profile doesn't match application identifier  profile doesn't match application identifier
Updating using AngularJS
Updating using AngularJS  Shopping.html <!DOCTYPE HTML PUBLIC... one more button for updating items in the table for Updating Items in Shopping.html. On clicking updating button for each row ( as like Remove button in each
updating a table in a database - SQL
updating a table in a database  give me complete source code in java to execute the sqlquery such that (update table_name set phone no=? where cous_id=?). or in simple way give me source code to update my table in MsAccess
Updating multiple value depending on checkboxes
Updating multiple value depending on checkboxes  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
Problem in updating query in Hibernate - Hibernate
Problem in updating query in Hibernate  Hi, I have used a query to update the existing columns of one table. The query updates the records in the main table but it does not update the tables that are mapped from the main table
Updating from MySQL 5.0 to 5.5 cPanel
Updating from MySQL 5.0 to 5.5 cPanel   Updating from MySQL 5.0 to 5.5 cPanel
Uploading a Profile with image[file] into a sql database
Uploading a Profile with image[file] into a sql database  I need to upload a file along with the some text into a database ......[ Similar to http://www.roseindia.net/jsp/jspfileupload/employeeuploadprofile_image.shtml
updating an access database with visual basic 2010
updating an access database with visual basic 2010  I am building a program in visual basic 2010 that connects to an access database. I was wondering if you could help me figure out the code for the save button. When
how to code-updating some details n some details r unchanged
how to code-updating some details n some details r unchanged  i have... : bloodgroup : my requirement is to update the details of user. and i had written the update query,but with that query all the details are updating... my doubt
updating column automatically based on system date
updating column automatically based on system date  hi, can any one give solution for my question i have a table called leave balanced(leave-id,leave balance,etc are column),in leave balance column each employee has some leave
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am having a multithreaded process which replicates the data from many table to one... inserting/updating to database. I dont know what is the issue but it was never
Save profile and image to mysql database, and view the image in another jsp page
Save profile and image to mysql database, and view the image in another jsp page  Pls. need help in saving the profile info with the image in mysql database.. some basic code pls in jsp... thanks in advance
Advertisements
 

 

 

DMCA.com