hi,
i am attaching the code of the html page calling the servlet and the servlet code ,please help me with the problem
html page code:
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="http://localhost:8080/examples/servlet/booklist">
<p><input type="submit" value="ShowBooks" name="B1"></p>
</form>
</body>
</html>
servlet code:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class booklist extends HttpServlet
{
Connection dbconn;
Statement st;
ResultSet rs;
PrintWriter pw;
public void init(ServletConfig cfg) throws ServletException
{
try
{
super.init(cfg);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbconn=DriverManager.getConnection("jdbc
dbc:bookstore");
}
catch(SQLException se)
{
}
catch(ClassNotFoundException ce)
{
}
}
//public void service(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
//{
//doPost(request,response);
//}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
try
{
st=dbconn.createStatement();
String query = "Select a.lastname,a.firstname,b.isbn,c.title,d.name from authors a,auth_books b, books c,publishers d where a.authid=b.authid AND b.isbn = c.isbn AND c.pub_code = d.pub_code";
rs = st.executeQuery(query);
response.setContentType("text/html");
pw = response.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("<title>");
pw.println("List of Books ");
pw.println("</title>");
pw.println("</head>");
pw.println("<body bgcolor = lightblue>");
pw.println("<table border=1>");
pw.println("<tr><th>ISBN</th><th>Title</th><th>Author</th><th>Publisher</th></tr>");
while(rs.next())
{
pw.println("<tr>");
pw.println("<td>");
pw.println(rs.getString("isbn"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("title"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("lastname")+""+rs.getString("firstname"));
pw.println("</td>");
pw.println("<td>");
pw.println(rs.getString("name"));
pw.println("</td>");
pw.println("</tr>");
}
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
}
catch(SQLException se1)
{
}
}
public void destroy()
{
try
{
pw.close();
rs.close();
dbconn.close();
}
catch(Exception e){}
}
}
thanks for the help
raghav