Pritam Banerjee

Greenhorn
+ Follow
since May 08, 2002
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 Pritam Banerjee

hello,
I have a form generated by a JSP page.
The form contains a few (7-8) fields.
When the page is submitted it goes to a servlet and finally the request gets forwarded to the next JSP that renders the next html.
There is a cancel button in the next page (that is effectively doing history.back() in the onClick event). When this cancel button is clicked the request is again going to the server (instead of the browser taking it from it's local cache) and hence the form in the previous page is reloaded with all fields empty. This means the user would have to re-type all fields.
The same thing works fine in Netscape, but the reload of the previous page on history.back() is happening for IE browser only.
How do I make sure that the previous page form doesn't reload ?
I haven't used any META tags like expires or no-cache, no-store etc.
Any help would be appreciated.
Regards,
Pritam
18 years ago
JSP
That's because the forward(req, res) method of RequestDispatcher takes the request and the response of the current HTTP request to the JSP. It is like forwarding the same Http request.
On the other hand, sendRedirect(urlStr) actually sends a completely new Http request to the server (to the new URL, the JSP in this case) and it abandons all parameters in the current HttpServletRequest object.
So, no wonder, you get the null value for the parameter in the JSP.
There is no way you can pass the current request parameters to the redirected URL, unless you put them in the session. But that's a lil clumsy way to do it ;-)
Pritam
19 years ago
Jonathan,
Actually this is the way we solved the same problem in one of our applications.
Are you sure that the thread you start at the start of the servlet is actually running. You can probably send '.' (dots) instead of space and check out if you get them (the dots) in the browser. If the browser is continously getting something (even if blank spaces) there is no reason why it shoud timeout.
19 years ago
Jessica,
Thanks for the reply.
If I have a time-out set in the server configuation as 20 minutes (since that is what we want to keep for rest of the application), and I use setMaxInactiveInterval() only for one servlet (the one that does huge processing) to make it 40 minutes.
Which one of these time-outs would get preference ?
I am using weblogic 5.1.
19 years ago
API docs say that the lastAccessTime of a HttpSession object is updated when a request is received from the client.
Session timeout is calculated starting from the lastAccessTime of the session.
I have set a session timeout of 20 minutes. A client requests a report. The report is huge, starts displaying immediately in the browser but takes 30 minutes to be completely displayed.
After the report is displayed, now the user clicks on links in the reports to dig further in and gets a session timeout error.
That means the lastAccessTime is not getting updated when the servlet is still writing output to the browser.
Is there a way to update the session lastAccessTime directly from the servlet code ?
I tried setMaxInactiveInterval(), but doesn't solve the problem.
Regards,
Pritam
19 years ago
But if you know in which condition you need to redirect to an ASP file then under that condition simply include() without setting the content type.
if(condition to go to ASP){
RequestDispatcher rd = getServletContext().getRequestDispatcher(fileName);
if(rd != null)
rd.include(req, resp);
}
else{
String mimetype = "application/pdf";
resp.setContentType(mimeType);
RequestDispatcher rd = getServletContext().getRequestDispatcher(fileName);
if(rd != null)
rd.include(req, resp);
}

This works. I guarantee you.
19 years ago
I'm able to download files with size uptoseveral MB's without any problem. Can you share your basic code, for us to check ?
19 years ago
Yes, it is possible to set the content type for the file you would like to show to the user.
Code example as follows:
String mimetype = "application/pdf";
resp.setContentType(mimeType);
RequestDispatcher rd = getServletContext().getRequestDispatcher(fileName);
if(rd != null)
rd.include(req, resp);
Note: You don't redirect to the file, rather you just include the file as part of the current response. That way you are eligible to set the content type.
Also the include() statement should be the last line of your doPost() or doGet(), since you just want to display the file and nothing before or after that.
Hope this helps.
Regards,
Pritam
19 years ago
Jonathan,
There is a common soltion to this problem of timeout. That has got nothing to do with the web/ application server you host your servlets. It will work everywhere.
You have to write a Thread of your own. Pseudo code as follows:
----------------------------------------------
class KeepAliveThread extends Thread{
PrintWriter out;
boolean stillProcessing;
KeepAliveThread(PrintWriter out){
this.out = out;
stillProcessing = true;
}
public void run(){
while(stillProcessing==true){
out.write(" ");
try{
Thread.sleep(2000);
}
catch(InterruptedException e){}
}
}

}

------------
Now your doPost() or doGet() in your servlet code should be like this:
public void doPost(HttpServletRequest req, HttpServletResponse resp){
{
//start the thread that sends sapces to keep connection alive with the browser
PrintWriter out = resp.getWriter();
KeepAliveThread kth = new KeepAliveTHread(out);
kth.start();
//do Processing by calling other methods etc
//end proc essing, before displaying the results or before forwarding to a JSP
kth.stillProcessing = false;
while(kth.isAlive());
// Now display the results
}
------------------
Since HTML ignores all spaces before <HTML> tag, the display will be perfect and you can be sure that the browser will never timeout, even if the processing takes hours.
This solution will work in any platform.
regards,
Pritam
19 years ago