Hi
I have this issue with passing a value from one servlet to another servlet. the situation is is this.
i have a servlet
tstret.java which say..pulls out all the employee_id(s) from a table and displays it as hyperlinks( using the anchor tag.).
now when i click on the hyperlink say
T001
, The control is passed to another servlet which pulls out all the info about employee id
T001
.
the problem i have is in the
tstret.java servlet. i am passing the employee_id as a parameter in the href path itself as shown below.
out.println("<td ><a href=\"http://localhost:7000/servlets-examples/accept_requisition.html?id="+[u]rs.getString(1)[/u]+"\" ><em>"+rs.getString(1)+"</em></a></td>");
now if you see the code i am trying to pass the employee_id by attaching it to a variable id and passing it with the url, it gives me a sql exception saying no data found .
if i pass a string say "rajiv" which i defined at the begining of code then i am able to pass it to the next servlet/html.
the full code is as follows
file : tstret.java
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class tstret extends HttpServlet
{
PrintWriter out;
String[] employee_identity;
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
try
{
response.setContentType("text/html");
out = response.getWriter();
String session_name="SHOBA";//request.getParameter("session_name");
out.println("<html><head><title> My Jobs </title></head>");
out.println("<body bgColor=#ececec leftMargin=10>");
out.println("<table align=center>");
out.println("<tr align=center><td><img src=\"http://localhost:7000/servlets-examples/images/topbar.gif\"></td></tr>");
out.println("<td>Jobs for : "+session_name+"</td>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:tst","scott","tiger");
Statement statement=connection.createStatement();
ResultSet rs= statement.executeQuery("select req_no from require_info where sent_to = " + "\'" + session_name + "\'");
// out.println("Jobs for : "+session_name);
while(rs.next())
{
/* String[] get_id={"shoba","ping","ting","ving"};
for(int i=0;i<get_id.length;i++)
{*/
out.println(" <tr align=\"center\">");
// out.println("<td><a href=\"servlet/testhyper\" name="+rs.getString(1)+"><em>"+rs.getString(1)+"</em></a></td>");
out.println("<td ><a href=\"http://localhost:7000/servlets-examples/accept_requisition.html?id="+rs.getString(1)+"\" ><em>"+rs.getString(1)+"</em></a></td>");
out.println("</tr>");
out.println("<br>");
// }
}
}catch(SQLException se){out.println("sqlexception"+se);}
catch(ClassNotFoundException ce){out.println("cnfexception"+ce);}
out.println("</table></body></html>");
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
doGet(request, response);
}
}
Can some one help me and see if there is anything i missing or doing wrong.
thanks in advance