I am doing some manipulation on servlet and set the same in session and i use the value when i redirect to some page. but while redirecting to the page the values are not coming,
I know that this is very basic question but still i am unable to do.
here is my servlet :
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String path = getServletContext().getRealPath("/accesscarddata/");
doGet(request, response);
readFile(request, response);
prepareExcelEmployeeListToMap(request, response);
classifyEmployeesMapEntries(request, response);
prepareReport(request, response);
generateLeaveReport(request,response);
//request.getRequestDispatcher("upload.jsp").forward(request, response);
response.sendRedirect("upload.jsp");
}
I tried these both but the values are not coming in jsp.
EDIT :
This is how i read from session in jsp
<%@ page contentType="text/html"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
String leaveReport = "";
if ((session.getAttribute("leaveReport") != null)) {
leaveReport = (String) session.getAttribute("leaveReport");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Comparing access-card Data with leave manager Data</title>
<link href="css/sling.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src='script/cal.js'></script>
<!-- Below imports for Blanket purpose-->
<script src='script/blanket.js'></script>
%>
this is how i try to get the value while loading the page, firt time the javascript alert is shown but the alort is not shown when the request is redirected from servlet.
bodyOnLoad();
function bodyOnLoad(){
alert("bodyOnLoad");
var leaveReport = '<%=leaveReport%>';
alert("leaveReport :"+leaveReport);
if(leaveReport!=null && leaveReport!=""){
displayLeaveReport(leaveReport);
}
}
and this is what is my javascript method :
function displayLeaveReport(leaveReport){
if(leaveReport == ""){
document.getElementById("leaveReport").style.display = "none";
} else{
document.getElementById("leaveReport").style.display = "";
}
}
JSP :
<tr>
<td width="100%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="title_box" align="left">Leave to be availed Employees</td>
</tr>
</table>
<table width="100%" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="left" class="tableBorder" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f9fae3" >
<tr class="lightrow">
<td width="10%" class="title_sub" align="center">S.No</td>
<td width="35%" class="title_sub" align="center">Employee ID</td>
<td width="35%" class="title_sub" align="center">Employee Name</td>
<td width="20%" class="title_sub" align="center">Action</td>
</tr>
</table>
<div id="leaveReport" align="right" style="display : none;height:100px; overflow:auto"></div>
</td>
</tr>
</table>
</td>
</tr>
It is possible to set values in div tag if you use ajax technogies like dwr,if not it is not possible to set values in div tag, change your code like follows in jsp and the vlaues will be displayed.