• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP- Servlet - File Streaming  RSS feed

 
Nishant Vartak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to display a JSP which will include some JSP (like menu jsp, header jsp) etc. These JSPs will be paint the left hand side and bottom side of page. In the remaining section, i should be able to display the OutputStream.

If this OutputStream is a HTML File, it should be displayed on the screen. If is a PDF/CSV/XLS, it should be available as download.
Can someone suggest how this can be achieved?

My Solution though not effective: As I can figure it out I will have to make two servlet call. First a call to Master Servlet to display the Master JSP (which will display all included JSP) and then other call to a different Servlet (Stream Servlet) to recieve a stream file.
I tried to invoke the Stream Servlet through "IFRAME" , but failed as it just invokes Servlet's init() method.


Some More info Can someone tell me which amongst the below mention files can be displayed with out installation of any third party software in browser as inline?
PDF,HTML,CSV,XML,RTF,XLS etc.
Our SearchWe have found that to display PDF inline, we need a Adobe Activex Plugin installed for respective browser. So PDF will be a presented as dowbnload.

Thanks and Regards,
Nishant Vartak
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66260
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nishant Vartak:
I tried to invoke the Stream Servlet through "IFRAME" , but failed as it just invokes Servlet's init() method.

It is perfectly valid to reference a servlet from an iframe. If it's the first time the servlet has been invoked, the init() method will be called. The response will be displayed in the iframe.
 
Nishant Vartak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Missed out on certain aspects. The Stream is stored in session. So i need to get access to HttpRequest object to get the stream from session. Can you suggest a way by which i can invoke either a get or a post method through iFrame?

Also, does Websphere Application Server support "iFrame" in a JSP.
iFrame works with tomcat on my browser (IE 6.0). So browser not supporting iFrame is rule out.

Thanks and Regards
Nishant V
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iframes are a client side concept.
Application servers don't need to support them.
They don't know what they are.

Iframes, and frames in general, to the server are nothing more than HTTP requests. Think of it as the browser loading one page inside another.
As long as the browser supports them you can use them with any server.

Can you explain what you mean by "the stream is stored in session"?
Connections, streams, file handles, etc.. are generally not good candidates for session scoped objects.
 
Nishant Vartak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i issue a request to Servlet(Master) it returns me a OutputStream. I cannot directly display this OutputStream by passing it to ServletStream as in that case the Servlet will display only the contents of this stream.
I need to display a master JSP and in one of its frame show the contents of this stream.
So the only solution which we could think of is store the OutputStream object in session in servlet(Master) and return with Master JSP.
Then in Master JSP have a iFrame which will invoke a Servlet (Streaming Servlet). The output from this Servlet will be a Stream which was set in session by Master Servlet.

iFrame will call 'init' method of Servlet. To overcome this problem we make iframe call a JSP which will auto submit to this Servlet (Streaming Servlet). This is achieved by calling a javascript function on "onLoad" event of HTML.

Let me know if there is a easier solution for this problem.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nishant Vartak:
So the only solution which we could think of is store the OutputStream object in session in servlet(Master) and return with Master JSP.


A more typical way of handling this is to wait until the child frame is called to generate the output stream.

We have an example in the servlet section of our codebarn that has an HTML page with links to some images. When one of the links is clicked, the browser makes a request for the image. The StreamServlet then reads the file (using getResourceAsStream) and streams it directly to the browser by writing it to the servletOutputStream.

That HTML page could easily be converted to a frameset by using the href from the hyperlinks as the src attributes for the frame tags.
 
Nishant Vartak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WE don't have a file, but Stream of data. This can be of any content-type - HTML,CSV,XML,PDF. We want to display it only if its a HTML , for rest we will have to give a Save As option to user. This can be achioeved by setting "content-disposition" as "inline" and "attachment" resp. This logic will be present in my (Streaming) Servlet. The OuputStream which needs to be passed to this (Streming)Servlet is generated in Other Servlet (Master Servlet). The responsiblity of Master Servlet is to display Master JSP. Master JSP includes a set of JSP and to display Stream it will invoke Streaming Servlet through iFrame.
Can someone suggest how this can be achieved. i.e inter-Servlet communication through JSP. withouty passing the "OutputStream" object into session.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!