Dipanjan Paul

Greenhorn
+ Follow
since Nov 16, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dipanjan Paul

Sorry to have not explained the problem fully. Its been damn frustating from yesterday.
This is what the problem is. When the following code gets executed the output HTML is like the following.
<HTML>
<HEAD>
<TITLE>Search Results</TITLE>
</HEAD>
<BODY>
<table width='100%' border='0' cellspacing='5' cellpadding='2'>
<TR> <TH align='center'>Items Chosen from Gallery </TH> </TR>
<TR> <TD>
</table>
</BODY> </HTML>
The stuff from the database that I am trying to display is not getting formatted into the HTML.
But if the following line in the code
out.println("<a href='http://dpaul004:9090/servlet/ServletB?Item_Name=" + rec.getString("Item_Name") + "'>" + rec.getString("Item_Name") + "</a> <br>");
is coded as
out.println("<a href='http://dpaul004:9090/servlet/ServletB'>" + rec.getString("Item_Name") + "</a> <br>");
the output is perfect like the following
<HTML>
<HEAD>
<TITLE>Search Results</TITLE>
</HEAD>
<BODY>
<table width='100%' border='0' cellspacing='5' cellpadding='2'>
<TR> <TH align='center'>Items Chosen from Gallery </TH> </TR>
<TR> <TD>
<a href='http://dpaul004:9090/servlet/ServletB?Item_Name=a123'>Book1</a> <br>
Current Bid:10.0000<br>
Ends On:2000-12-01 00:00:00<br>
</TD> </TR>
<TR> <TD>
<a href='http://dpaul004:9090/servlet/ServletB?Item_Name=a123'>Book2</a> <br>
Current Bid:20.0000<br>
Ends On:2000-12-01 00:00:00<br>
</TD> </TR>
</table>
</BODY> </HTML>
Please help Thanx Dipanjan
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>");
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>");
out.println("<a href='http://dpaul004:9090/servlet/ServletB?Item_Name=" + rec.getString("Item_Name") + "'>" + rec.getString("Item_Name") + "</a> <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();
}
catch(Exception e)
{
}
out.println("</table>");
out.println("</BODY> </HTML>");

out.close();
}
}
23 years ago
In the following code I am trying to pass the parameter Item_Name to ServletB (in the href= ...). If I dont use the parameter (i.e ?Item_Name = ...) the code works fine. Can anyone please tell me why this is happenning.
Tx

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>");
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>");
out.println("<a href='http://dpaul004:9090/servlet/ServletB?Item_Name=" + rec.getString("Item_Name") + "'>" + rec.getString("Item_Name") + "</a> <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();
}
catch(Exception e)
{
}
out.println("</table>");
out.println("</BODY> </HTML>");

out.close();
}
}
23 years ago
I am trying to test my servlets using Java Web Server. After I load the servlet and try to run it, it runs fine. But if I modify the servlet code, recompile it and try to rerun the servlet the old copy of the servlet gets executed (whichever was loaded previously). However if I shut down the webserver and restart and then try to rerun the servlet, it takes the modified version of the servlet and executes it.
Can anyone please tell me why is this happenning.
Thanx
23 years ago
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();
}
}
23 years ago
Hi,
I am new to servlets and I am using javawebserver2.0. I have written a program which si going to use the database wich is in mycase a text file and I am trying to use the database abut I am not being able to. The program is getting compiled but when I try to run it is showing a 501 error. I am attaching the program alongwith.I need urgent help on this.
thankximport java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.*;
public class ServletA extends HttpServlet
{
Connection dbcon;
public void init() throws ServletException
{
try
{
String driver = getInitParameter("JdbcDriver");
String dbURL = getInitParameter("dbURL");
Class.forName(driver);
dbcon = DriverManager.getConnection(dbURL,"","");
}
catch (ClassNotFoundException e)
{
System.out.println("DB Driver not found");
System.out.println(e.toString());
throw new UnavailableException(this, "DB Driver class");
}
catch (SQLException e)
{
System.out.println("Error in connect");
System.out.println(e.toString());
throw new UnavailableException(this, "Cannot connect");
}
}

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>");
try
{
Statement st=dbcon.createStatement();
ResultSet rec=st.executeQuery(
"Select Item_Name,Item_Number "+
"from Items");
while(rec.next())
{
out.println("Item_Name:" + rec.getString("Item_Name"));
out.println("Item_Number:" + rec.getString("Item_Number"));
}
st.close();
}
catch(Exception e)
{
}
out.println("</BODY></HTML>");

out.close();
}
}
,
dp
23 years ago