jsp - Java Servlet Pages -


i have jsp file called display.jsp. written code , getting result seeing snapshot, displaying user_details have in database. have edit button. query is, if click edit button on particular user, need form showing textfields firstname, lastname, dob, address, username, password should pre-filled in textfields fetching display.jsp.

here code display.jsp:

<%@ page import="java.sql.*" %> <%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en"          "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">  <title>login details</title>   </head>  <body>  <body bgcolor="yellow">  <form method="get" id="my_form"></form>  <table border="1" width="50%" height="30%">  <tr> <th><font color='red'>firstname</font></th> <th><font color='red'>lastname</font></th>  <th><font color='red'>dob</font></th>  <th><font color='red'>address</font></th>   <th><font color='red'>username</font></th>  <th><font color='red'>password</font></th>   </tr>   <%  class.forname("com.mysql.jdbc.driver");  connectioncon=drivermanager.getconnection("jdbc:mysql://localhost:3306  /","root","scott");     statement stmt=con.createstatement();   resultset rs=stmt.executequery("select *from come2links.user_details");      while(rs.next())     {       string fisrtname=rs.getstring("firstname");        string lastname=rs.getstring("lastname");       date dob = rs.getdate("dob");       string address=rs.getstring("address");       string username=rs.getstring("username");      string password=rs.getstring("password");      %>     <tr>    <td><b><font color='#663300'><%=fisrtname%></font></b></td>     <td><b><font color='#663300'><%=lastname%></font></b></td>    <td><b><font color='#663300'><%=dob%></font></b></td>     <td><b><font color='#663300'><%=address%></font></b></td>    <td><b><font color='#663300'><%=username%></font></b></td>    <td><b><font color='#663300'><%=password%></font></b></td>      <td>            <form name="f1" action="update.jsp" >             <input id="edit1" type="submit" value="edit">            </form>    <%       }   %>    </tr>    </table>    </body>   </html> 

add hidden in form this:

<form name="f1" action="update.jsp" >    <input type="hidden" name="recordid" value="<%= yourrecordid%>">    <input id="edit1" type="submit" value="edit"> </form> 

note yourrecordid must value primary key or unique key field in table. guess table has one. in update.jsp, can build jsp similar display.jsp replacing query with

resultset rs=stmt.executequery("select * come2links.user_detailswhere uniquekeyfield='"+request.getparameter("recordid")+"';"; 

then changing labels textboxes inputs. these textboxes must inside form in addition hidden input contain request.getparameter("recordid"). use page actual update.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -