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



Home Answers Viewqa JSP-Servlet How to get table row contents into next jsp page
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas
How to get table row contents into next jsp page
2 Answer(s)      2 years and 2 months ago
Posted in : JSP-Servlet


Hi, I have a 30 radio button and values populating dynamically from the database.Now when i select a particular radio button and select on sub menu item , it goes to next jsp page.But the problem is how do i get the selected radio button table row contents in the next jsp page and display them

Thanks Vikas


Advertisement
View Answers

July 10, 2012 at 10:43 AM


The given code retrieve data from database and display in the html table. At each row, there is a radio button. When the user clicks the particular radio 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><input type="radio" name="name" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

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>


July 10, 2012 at 10:44 AM


continue..

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:
How to get table row contents into next jsp page
How to get table row contents into next jsp page  Hi, I have a 30... page.But the problem is how do i get the selected radio button table row contents in the next jsp page and display them Thanks Vikas   The given
How to print contents of a web page in jsp?
How to print contents of a web page in jsp?  I have generated a pay slip using jsp.How do I print the contents of the slip
Advertisements
How to search the selected item in row table using radia button in JSP?
How to search the selected item in row table using radia button in JSP?  How to search the selected item in row table using radia button in JSP
include a delete option in every row of table in a JSP page
include a delete option in every row of table in a JSP page  I have the following code of a JSP page........... <blockquote> <p>&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> &lt
How to change table row color when click on Hyper Link in jsp?
How to change table row color when click on Hyper Link in jsp?  I use 5 links: Link 1 Link 2 Link 3.. table: row1 row2 row3.. when click on the link1 automatically change
How to know the selected row from table - JSP-Interview Questions
How to know the selected row from table  hi Every one....i am... place one table data as hyperlink. now the problem here is how can i know the selected row in that table.  Hi Friend, Please clarify your
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript  when click on the next... for your answer http://nscraps.com/Java/557-pagination-jsp-page-example-code.htm
how to insert the bulk data into the data base from the table of jsp page to another jsp page
and i have to insert the mark for n number student in the table i don't how to get values in array in next jsp page and insert into the row by row Please do...how to insert the bulk data into the data base from the table of jsp page
how to get data in jsp page - Framework
how to get data in jsp page  Hi List[], I to get the data in jsp page by calling mxml file using FDS. Please give example to me... to enclose a set of MXML tags in a JSP page. You can set any number
how to get the next option - Java Beginners
how to get the next option  i was getting values from the database it was bulk so i want to keep the next option how to do in the jsp  ... the following link: http://www.roseindia.net/jsp/navigation-database-table.shtml
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
How to Dragging and dropping HTML table row to another position(In Jsp... have one Html table in jsp page and i am iterating values (in columns of html table)from Database, Now i am Dragging and dropping one HTML table row to another
please give me solution how to display next page after 20 records ? - JSP-Servlet
please give me solution how to display next page after 20 records ?  ...; if(row==4){ document.links("next"+document.request.preRow.value).disabled... true; } function hideRow(type) { row=document.request.preRow.value
How to Extract row from table view using JSP Code - Java Beginners
How to Extract row from table view using JSP Code  Hi Friends... to java world and trying to design a web page using NetBeans IDE 6.8. My problem exist with retrival of row from a table on click of link. Table Structure
How save,get picture from database in my jsp page?
How save,get picture from database in my jsp page?  How i save picture in db after browsing it,and also how i get it on my other jsp page
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
change database values when click next button on jsp page
change database values when click next button on jsp page  How to retrive database values rondomly and display jsp page ,when user click next and previous bottons change the values on jsp page
to display single row from database and next to display other question - JSP-Servlet
, but i am facing a problem while retieving the next question in the jsp page. its...to display single row from database and next to display other question  Hi all, I am using JSP with MYSQL backend. In my project we have 100
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
show folder on server by clicking a row in table using jsp and ajax
show folder on server by clicking a row in table using jsp and ajax  Hi, i want a jsp page which has one dropdown and one textfield. when i click... display the table. Now if i click on a row it should open a folder in server
show folder on server by clicking a row in table using jsp and ajax
show folder on server by clicking a row in table using jsp and ajax  Hi, i want a jsp page which has one dropdown and one textfield. when i click... display the table. Now if i click on a row it should open a folder in server
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
JavaScript add row dynamically to table
. In this example we will describe you how to add row dynamically to the table... and into this page we have created a table with one row. We have one button "Add... JavaScript add row dynamically to table  
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
How ot get a web page title and meta tags in java(jsp/ servlet) - JSP-Servlet
How ot get a web page title and meta tags in java(jsp/ servlet)  Hi i want to get a web page title and meta tags using servlet of java but i am... with img not the complete web page
JavaScript add row to table
will get the table containing the columns Name and Address and a button 'Add row... JavaScript add row to table       This section illustrates you how to add a new row to the existing
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.  Initially,display 7or10 records on a jsp pageand when click on the NEXT button(or href link) then display next 7 records
PHP file_get_contents() Function
PHP file_get_contents() Function  Hi, How do i read the content of file using PHP program? So kindly provide any example or online help reference for filegetcontents() Function in PHP. Please feel free to suggest. Thanks
Java get Next Day
Java get Next Day       In this section, you will study how to get the next day in java... DateFormatSymbols in order to get the names of the days of the week. The method getWeekdays
Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database
Dragging and dropping HTML table row to another position(In Jsp) and save... table in jsp page and i am iterating values (in columns of html table)from Database, Now i am Dragging and dropping one HTML table row to another position.I
how to display the selected row from the data table in model panel ??
how to display the selected row from the data table in model panel ??  the below displayed is my datatable:tableDatas.xhtml <rich...(); return dataList; } please help me out !~!!!!! i get the model panel but the values
 

 

 

DMCA.com