Solved

HttpServlet

Posted on 2006-06-27
5
295 Views
Last Modified: 2011-04-14
I have a servlet which streams content to the brower using
response.setDateHeader("Last-Modified", DateUtils.now().getTime());
response.setHeader("Expires", "-1");
response.setContentType(contentTYpe);
response.setHeader("Content-Disposition", "attachment; filename=" +fileName);

I have an if condition which only does the above if there is content to stream. This content comes from the database.
If there is content it works as it should, ie displays a dialog window to open or save.

If there is no content then I just want to return from this servlet. What happens is that the browser points to this servlet

eg.

http://localhost:7001/cart/dowloadServlet

What i want is the original jsp to display where the user clicks to do the download.
Any ideas?
0
Comment
Question by:inzaghi
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
colr__ earned 375 total points
ID: 16993910
Can you not just redirect them to the original jsp url?

if (noContent){
response.sendRedirect("original.jsp");
return;
}
0
 

Author Comment

by:inzaghi
ID: 16993939
this would work but how come it does not automatically return control to the original jsp, similar to when you are asked to save/open the attachment.
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 125 total points
ID: 16999333
This is probably be done because the jsp points to the servlet. You first go to the servlet, the browser sees that there is no content and it stays in the servlet.
0
 
LVL 8

Expert Comment

by:colr__
ID: 16999343
If the original page is called original.jsp, then control should be returned to that page with the above code. The save/open dialogue should only appear if a file is abouyt to be downloaded, but since ther isnt one (in the case where there is no content), then you'll have to select a different file, am I right? Does original.jsp not do this?
0
 
LVL 35

Expert Comment

by:girionis
ID: 17000759
:)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
what is a "java.lang.System Property"   ? 20 65
oracle 11g 23 73
how to install java on RHEL image on EC2 4 26
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now