Hello,
I am new to
servlets and I am trying to do a project where I am using
java servlets.import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ServletA extends HttpServlet
{
Connection dbCon;
public void init() throws ServletException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbCon = DriverManager.getConnection("jdbc

dbc:MyDB");
}
catch(ClassNotFoundException e)
{
System.out.println("ItemsQuery

atabase driver could not be found.");
System.out.println(e.toString());
throw new UnavailableException(this,"Database driver class not found");
}
catch(SQLException e)
{
System.out.println("ItemsQuery:Error Connecting to the database");
System.out.println(e.toString());
throw new UnavailableException(this,"Cannot connect to the database");
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Search Results</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<table width='100%' border='0' cellspacing='5' cellpadding='2'>");
out.println("<TR> <TH align='center'>Items Chosen from Gallery </TH> </TR>");
out.println("<form action='http://localhost:8080/servlet/ServletB' method='get'>");
try
{
Statement st=dbCon.createStatement();
ResultSet rec=st.executeQuery(
"Select Item_Name,Current_Bid, End_Date "+
"from Items");
while(rec.next())
{
out.println("<TR> <TD name = 'it_name'>");
out.println("Item Name:" + rec.getString("Item_Name") + "<br>");
out.println("Current Bid:" + rec.getString("Current_Bid") + "<br>");
out.println("Ends On:" + rec.getString("End_Date") + "<br>");
out.println("</TD> </TR>");
}
st.close();
}
I am trying to use this page to have a list of all items and this page should have a hyperlink at the Items_Name parameter so that once the user clicks on this hyperlink it gets to the second servlet which is ServletB in my case.
Please help me how do i solve this problem and be done with the navigation.
thanks in advance,
DP
catch(Exception e)
{
}
out.println("</form>");
out.println("</table> </BODY> </HTML>");
out.close();
}
}