I have an index.jsp page with buttons named "refresh", "forward" and "edit". If I click on the refresh button then it call a Servlet and values are displayed on the index.jsp page.
When I click on the "forward" button it calls another servlet and goes to another page forward_call_log.jsp. In this page when I click on the "forward" button it calls another servlet and that servlet displays the index.jsp page. The index.jsp page is displayed but the values from the data base are not available.
How can i fix this problem?
index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pager Example - www.javaworkspace.com</title>
</head>
<body>
<form method="post" action="./Problem_retrive" >
<input type="submit" value="Refresh">
</form>
<form action="./edit_call_log" method="post">
<%
ResultSet rs=null;
try
{
rs=(ResultSet)request.getAttribute("rs");
//request.setAttribute("rs",rs);
if(rs.next())
{
%>
<table border=1 cellspacing=1 cellpadding=1>
<tr>
<th>check box</th>
<th>Problem ID</th>
<th>user ID</th>
</tr>
<%
do
{
%>
<tr>
<td><input type="checkbox" name="checkbox" value="<%=rs.getString(1) %>"></td>
<td><%=rs.getString(1) %></td>
<td><%=rs.getString(2) %></td>
</tr>
<%
}
while(rs.next());
%>
</table>
<%
}
else
{
out.println("hiiiiiiii");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<input type="submit" name="act" value="EditCall"/>
<input type="submit" name="act" value="Forward"/>
</form>
</body>
</html>
After click on the Refresh button call Edit_call_servlet.java
import database.problemdesc.Problem_retrive_class;
import database.user_master.User_master;
import java.sql.*;
public class Edit_call extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
HttpSession session = request.getSession(true);
ResultSet rs=null;
Problem_retrive_class prc=new Problem_retrive_class();
int checkbox=Integer.parseInt(request.getParameter("checkbox"));
session.setAttribute("problem_id", checkbox);
String act=request.getParameter("act");
if(act.equals("EditCall"))
{
try
{
rs=prc.select_table(checkbox);
RequestDispatcher rd = request.getRequestDispatcher("edit_call_log.jsp");
request.setAttribute("rs", rs);
rd.forward(request, response);
}
catch(Exception e)
{
e.printStackTrace();
}
}
else if(act.equals("Forward"))
{
System.out.println("Forward page");
try
{
ResultSet rs1=null;
User_master um=new User_master();
rs=prc.select_table(checkbox);
if(rs.next())
{
System.out.println("Value retrieve from PRC select_table");
rs1=um.select_table(rs.getString(7));
System.out.println("Value retrieve from PRC select_table"+rs.getString(7));
RequestDispatcher rd = request.getRequestDispatcher("forward_call_log.jsp");
request.setAttribute("rs1", rs1);
request.setAttribute("user_type", rs.getString(7));
rd.forward(request, response);
}
else
{
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
}
catch(Exception e)
{
}
}
}
}
After clicking on the Forward button call Problem_retrive_servlet.java
import database.problemdesc.Problem_retrive_class;
public class Problem_retrive extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
Connection con=null;
ResultSet rs=null;
try
{
Problem_retrive_class prc=new Problem_retrive_class();
DBBean db=new DBBean();
con=db.getDBConnection();
rs=prc.select_table();
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}