• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

re: how do i link my first servlet to the second and then to third etc?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is really just an HTML problem, not a servlets one.
The equivilent of:
out.println("<form action='http://localhost:8080/servlet/ServletB'
method='get'>");
expressed as a clickable link is something like:
<a href="http://localhost:8080/servlet/ServletB?param=value¶m2=value2" >Item Name Goes Here </a>
Which automatically goes to your doGet method.
Bill
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic