Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

new JSP session is created when trying to refresh the page

843838Jan 24 2007 — edited Jan 24 2007
in the code given below, if the 4th last line of code, i.e., iframe tag is commented out then the code is working fine. but when it is used and the page is refreshed, old session does not continue any more, instead a new session is created. please suggest what may be the problem?

<%@ page info="Cryoserver - Error" %>
<%@ page session="true" %>
<%@ page isErrorPage="true" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="ci.cryoserver.util.XML" %>
<%@ page import="ci.cryoserver.user.UserProfile" %>
<%@ page import="ci.cryoserver.frontend.JSP" %>
<%@ page import="ci.cryoserver.version.Version" %>
<%@ page import="ci.cryoserver.mail.MailDistributor" %>
<%@ page import="javax.mail.internet.InternetAddress" %>
<%@ page import="javax.mail.internet.MimeMessage" %>

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="nocache.jsp" %>
<%
System.out.println("session is "+session);
%>
<%!
String getAttribute (HttpServletRequest request, HttpSession session, String name) {
String s = request . getParameter (name);
if (s == null)
s = (String) session . getAttribute (name);
if (s == null)
s = "";
session . setAttribute (name, s);
s = XML.convertXMLSpecials(s);
return s;
}
%>
<%

request.setCharacterEncoding ("UTF-8");

ResourceBundle text = JSP.getResourceBundle(request, session);

UserProfile userProfile = (UserProfile) session.getAttribute( "profile" );

String authenticated = (String) session.getAttribute( "authenticated" );

application.log("error_redirected.jsp: userProfile is "+userProfile);
application.log("error_redirected.jsp: authenticated is "+authenticated);
System.out.println("1 session is "+session);
if ( authenticated == null || ! authenticated.equals("true") ) {
application.log ("error_redirected.jsp: Session was not authenticated ");
response.sendRedirect("login.jsp");
return;
}
System.out.println("2 session is "+session);
System.out.println("error_redirect.jsp.......trying to get exception");
exception = (Throwable)session.getAttribute("exception");
System.out.println("Cause of exception = " + exception.getCause());
System.out.println("3 session is "+session);

%><html>
<head>
<SCRIPT><!--
var ifrme = "";
function notify(doc) {
ifrme = doc;
popMessage();
}
function popMessage() {
var content = document.hiddenError.errorMessage.value;
if(ifrme!="") {
ifrme.open();
ifrme.writeln(content);
ifrme.close();
}
document.getElementById("errorBody").style.visibility="hidden";
}
function showHideError(a) {
a.blur();
var er = document.getElementById("errorBody");
if(er.style.visibility=="hidden") {
er.style.visibility="visible";
a.innerHTML = "<%=text.getString("error.hide_error_message")%>";
} else {
er.style.visibility="hidden";
a.innerHTML = "<%=text.getString("error.show_error_message")%>";
}
}
//--></SCRIPT>
<title><%=text.getString("global.product_name")%> - <%=text.getString("error.title")%></title>
<link href="cryoserver.css" rel="stylesheet" type="text/css">
<link rel="SHORTCUT ICON" href="favicon.ico">
</head>
<body>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#006699">
<tr>
<td align="left" valign="middle"><img src="images/logo.gif" alt="<%=text.getString("global.logo_alternative")%>" name="logo" width="168" height="65" border="0" align="middle" id="logo" /></td>
<td align="right" valign="top"><p class="h5white">(<%= Version.getVersion() %>)</p></td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#006699">
<tr>
<td>
<div class="navmain">
<div class="tab1Off">
<% if( userProfile!=null&&userProfile.getAdminLevel() == UserProfile.LEVEL_ADMINISTRATOR ) { %>
<p class="h5On"><%=session.getAttribute("welcome_page_name")%></p>
<% } else { %>
<p class="h5On"><%=session.getAttribute("welcome_page_name")%></p>
<% } %>
</div>
<div class="tab2">
<p class="h5Off"><%=text.getString("error.error")%></p>
</div>
</td>
</tr>
</table>

<div class="main">
<h2><%=text.getString("global.product_name")%> - <%=text.getString("error.title")%></h2>
<p class="error"><%=text.getString("error.an_error_has_occurred")%></p>
<form name="hiddenError" style="display:none">

<textarea name="errorMessage" style="display:none"><%
StringWriter writer = new StringWriter();
exception.printStackTrace( new PrintWriter( writer ) );
%><html><head><link href="cryoserver.css" rel="stylesheet" type="text/css"></head><body><pre><%= XML.convertXMLSpecials(writer.toString()) %></pre></body></html>
</TEXTAREA></FORM>

<!--
<p>
<% String errorRedirectURL = response.encodeURL("error_redirected.jsp"); %>
<a href="<%= errorRedirectURL %>?sendMail=true"">Click here to get an email of stack trace.</a>
</p>
-->

<input type="button" value="mail error stack trace" onClick="document.location.href='error_redirected.jsp?sendMail=true'">

<!-- check whether to send mail of stack trace or not -->
<% String isMail = request.getParameter("sendMail");
boolean mailSent = false;
if(isMail != null && isMail.equalsIgnoreCase("true")) {
// send a mail of stack trace
System.out.println("--------send a mail -----------------");

String companyTag = userProfile.getCompanyTag();
InternetAddress from = new InternetAddress((String) application.getInitParameter("mail.cryoserver_address"));
String subject = "Cryoserver exception stack trace";
String recipient = "ashish.sarna@prathamsoftware.com";
String body = "Stack trace for cryoserver exception \n";
// get complete stack trace
StackTraceElement[] stack = exception.getStackTrace();
for(int i=0; i<stack.length; i++) {
body = body + stack[i] + "\n";
}
MailDistributor md = new MailDistributor (application);
MimeMessage msg = md . createMessage (companyTag);
msg.setFrom (from);
msg.setRecipients (javax.mail.Message.RecipientType.TO , recipient);
msg.setSubject (subject);
msg.setSentDate (new java.util.Date ());
msg.setText(body);
try {
md.sendMessage(msg);
mailSent = true;
application.log("error_redirected.jsp: Stack trace email has been sent successfully");
}
catch(Exception e){
application.log("error_redirected.jsp: Exception in sending stack trace email " + e);
}
}
System.out.println("4 session is "+session);
if(mailSent) { %>
<p> Stack trace email has been sent successfully. </p>
<% } %>

<p><a onmouseover='window.status="Show/Hide error message"; return true;' onmouseout='window.status="";return true;' href='javascript:;' onclick='javascript:showHideError(this)'><%=text.getString("error.show_error_message")%></A><P>�</P></p>
<iframe style="width:100%;height:500;" name="errorBody" id="errorBody" leftmargin="0" topmargin="0" marginwidth="2" marginheight="2" src="iframe.html"></iframe>
</div>

</body>
</html>


Here is iframe.html which is being used in iframe:




<html>
<head>
<script><!--
function loadText() {
if(navigator.appName=="Microsoft Internet Explorer")
document.location.replace("");
parent.notify(document);
return;
}
//--></script>
</head>
<body onload="loadText()">
</body>
</html>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2007
Added on Jan 24 2007
1 comment
470 views