" name="description">

view jsp file (reference file). is the way of coding good ?

view jsp file (reference file). is the way of coding good ?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> View Retailer

<%@ page import="com.tcs.ilp.*" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="com.tcs.ilp.model.*" %> <%

ArrayList<RetailerBean> f=(ArrayList<RetailerBean>)request.getAttribute("list1"); %>

    <table border=2><tr><th>Retailer ID</th><th>Retailer Name</th><th>Retailer Licence</th><th>Address</th><th>Contact No.</th><th>Email ID</th><th>DOB</th><th>Username</th><th>Password</th></tr>

    <%
    for(RetailerBean x:f)
    {
    %>
         <tr><td><%=x.getId() %></td><td><%=x.getName() %></td><td><%=x.getLicence() %></td><td><%=x.getAddress() %></td><td><%=x.getContactno() %></td><td><%=x.getEmailid() %></td><td><%=x.getDob() %></td><td><%=x.getUsername() %></td><td><%= x.getPassword() %></td></tr>

    <%
    }
    %>
    </table>

View Answers

May 28, 2012 at 4:24 PM

The given code retrieves the data from the database and display it in html tables.

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<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>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>









Related Tutorials/Questions & Answers:

Ads