Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: how to show data in jsp page click on edit button

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    My Mood
    Happy
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Hello!

    i am beginner.
    i want to know how to data show in text box according click edit button.
    please help me.
    this is jsp file.



    <%@ 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">
    <%@page import="java.sql.*,java.util.*"%>
    <%!ResultSet rs = null;%>

    <html>
    <form method="post" action="insert.jsp">
    <table>
    <tr>
    <td>User Name:</td>
    <td><input type="text" name="uname"></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="pass"></td>
    </tr>
    <tr>
    <td>Retype Password:</td>
    <td><input type="password" name="repass"></td>
    </tr>
    <tr>
    <td>
    <tr>
    <td>Role:</td>
    <td><select name="ddrole" style="width: 110px">
    <option>Admin</option> -->
    <option>Editor</option> -->
    </select></td>
    </tr>

    <tr>
    <td>Date Input:</td>
    <td><input type="text" name="date"></td>
    </tr>

    <tr>
    <td></td>
    <td><input type="submit" value="Save" name="btnSave"></td>
    </tr>
    </table>
    </form>
    </html>

    <%
    String uname = request.getParameter("uname");
    String pass = request.getParameter("pass");
    String repass = request.getParameter("repass");
    String role = request.getParameter("ddrole");
    String date = request.getParameter("date");

    if (request.getParameter("btnSave") != null) {

    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/azurehouse", "root",
    "");
    Statement st = con.createStatement();
    int i = st
    .executeUpdate("insert into admin(username,password,role,date) values('"
    + uname
    + "','"
    + pass
    + "','"
    + role
    + "','" + date + "')");
    Statement s = con.createStatement();

    rs.close();
    st.close();
    con.close();
    }

    catch (Exception e) {
    System.out.print(e);
    e.printStackTrace();
    }
    }

    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection db = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/azurehouse", "root", "");
    Statement s = db.createStatement();
    rs = s.executeQuery("select * from admin");
    %>
    <table width="290" border="1" align="left">
    <%
    while (rs.next()) {
    String id = rs.getString(1);
    uname = rs.getString(2);
    pass = rs.getString(2);
    repass = rs.getString(4);
    role = rs.getString(1);
    date = rs.getString(1);
    %>
    <tr>
    <td width="20"><%=rs.getInt(1)%></td>
    <td width="20"><%=rs.getString(2)%></td>
    <td width="20"><%=rs.getString(3)%></td>
    <td width="20"><%=rs.getString(4)%></td>
    <td width="40"><a href=" id=<%=rs.getString(1)%>&action=edit"></a>
    <input type="submit" value="edit" name="btnedit"
    onclick="getElementById('action').value ='<%=id%>'"></td>

    <td width="40">Delete</td>
    </tr>



    <%
    }

    rs.close();
    s.close();
    db.close();
    } catch (Exception e) {
    //for now, just report the error to the system log
    System.out.println(e.toString());

    }
    %>

    </table>


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Hello!

    Please post your code correctly according to the instructions in this link.

    Attempt to post your code in the appropriate sub-forum.

    Give your threads appropriate titles.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    taytay (March 23rd, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    My Mood
    Happy
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default how to show data in jsp page click on edit button

    HTML Code:
    
    <%@ 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">
    <%@page import="java.sql.*,java.util.*"%>
    <%!ResultSet rs = null;%>
    
    <html>
    <form method="post" action="insert.jsp">
    <table>
    <tr>
    <td>User Name:</td>
    <td><input type="text" name="uname"></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="pass"></td>
    </tr>
    <tr>
    <td>Retype Password:</td>
    <td><input type="password" name="repass"></td>
    </tr>
    <tr>
    <td>
    <tr>
    <td>Role:</td>
    <td><select name="ddrole" style="width: 110px">
    <option>Admin</option> -->
    <option>Editor</option> -->
    </select></td>
    </tr>
    
    <tr>
    <td>Date Input:</td>
    <td><input type="text" name="date"></td>
    </tr>
    
    <tr>
    <td></td>
    <td><input type="submit" value="Save" name="btnSave"></td>
    </tr>
    </table>
    </form>
    </html>
    
    <%
    String uname = request.getParameter("uname");
    String pass = request.getParameter("pass");
    String repass = request.getParameter("repass");
    String role = request.getParameter("ddrole");
    String date = request.getParameter("date");
    
    if (request.getParameter("btnSave") != null) {
    
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/azurehouse", "root",
    "");
    Statement st = con.createStatement();
    int i = st
    .executeUpdate("insert into admin(username,password,role,date) values('"
    + uname
    + "','"
    + pass
    + "','"
    + role
    + "','" + date + "')");
    Statement s = con.createStatement();
    
    rs.close();
    st.close();
    con.close();
    }
    
    catch (Exception e) {
    System.out.print(e);
    e.printStackTrace();
    }
    }
    
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection db = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/azurehouse", "root", "");
    Statement s = db.createStatement();
    rs = s.executeQuery("select * from admin");
    %>
    <table width="290" border="1" align="left">
    <%
    while (rs.next()) {
    String id = rs.getString(1);
    uname = rs.getString(2);
    pass = rs.getString(2);
    repass = rs.getString(4);
    role = rs.getString(1);
    date = rs.getString(1);
    %>
    <tr>
    <td width="20"><%=rs.getInt(1)%></td>
    <td width="20"><%=rs.getString(2)%></td>
    <td width="20"><%=rs.getString(3)%></td>
    <td width="20"><%=rs.getString(4)%></td>
    <td width="40"><a href=" id=<%=rs.getString(1)%>&action=edit"></a>
    <input type="submit" value="edit" name="btnedit"
    onclick="getElementById('action').value ='<%=id%>'"></td>
    
    <td width="40">Delete</td>
    </tr>
    
    
    
    <%
    }
    
    rs.close();
    s.close();
    db.close();
    } catch (Exception e) {
    //for now, just report the error to the system log
    System.out.println(e.toString());
    
    }
    %>
    
    </table> 
    
    Last edited by taytay; March 23rd, 2014 at 02:19 AM.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to show data in jsp page click on edit button

    Please don't post duplicate threads, but thank you for improving the original.

    Threads merged.

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    taytay (March 23rd, 2014)

  7. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    5
    My Mood
    Happy
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: how to show data in jsp page click on edit button

    why i can't see code in following link "edit page in servlet/jsp".

Similar Threads

  1. edit page in servlet/jsp
    By magashi in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 28th, 2013, 10:02 AM
  2. [SOLVED] CardLayout show a specific card with button click
    By IanSawyer in forum AWT / Java Swing
    Replies: 2
    Last Post: April 13th, 2012, 11:07 AM
  3. Display data from list on same jsp page
    By reubenmk in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: February 13th, 2012, 03:54 AM
  4. Replies: 6
    Last Post: December 6th, 2011, 08:46 AM
  5. how can i display my data on jsp page in struts2
    By shekhar16 in forum Web Frameworks
    Replies: 0
    Last Post: March 4th, 2011, 06:26 AM