Home Tutorial Jsp JSP hide and show tables

 
 

JSP hide and show tables
Posted on: December 20, 2012 at 12:00 AM
Advertisement
In this tutorial, you will learn how to hide and show html tables using javascript in jsp.

JSP hide and show tables

In this tutorial, you will learn how to hide and show html tables using javascript in jsp. Here is an example of simple jsp code which is having a table consists of database data and a Go button. Using the style attribute, we have made table invisible. But, when the user click Go button, table will be visible with all the data.

Example:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<script>
function sh(){
document.getElementById("tab").style.visibility="visible";
}
</script>
<input type="button" value="Go" onclick="sh();"><br>
<table border="1" id="tab" style="visibility:hidden;">

<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee";
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>Contact No</td><td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td><td><input type="text" name="email" value="<%=rs.getString("email")%>"></td></tr>
<%
}
}
catch(Exception e){}
%>
</table>
Advertisement

Related Tags for JSP hide and show tables:


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: December 20, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com