aspose file tools*
The moose likes JSP and the fly likes how to display the allformat files on the browser using jsp or servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to display the allformat files on the browser using jsp or servlets" Watch "how to display the allformat files on the browser using jsp or servlets" New topic
Author

how to display the allformat files on the browser using jsp or servlets

mohan cheepu
Ranch Hand

Joined: Nov 15, 2007
Posts: 49
i devleoped code .i display the image file and pdf file displayed on the browser if i use internet explore. i use firefox ,just downloading.
my code .please hlep to me. how display allfile formats on browser.give me source code.
<%@ page language="java" %>
<%@ page import="java.io.*"%>


<html>
<body> 

<% String ss=request.getParameter("file"); %>

<%


String fname ="d:/"+ss;
response.setHeader("Content-Disposition", "attachement; filename=\""+ss+"\"");


InputStream isStream = null;
ServletOutputStream sosStream = null;
try
{
response.flushBuffer();
isStream =new FileInputStream(fname);
sosStream =response.getOutputStream();
int ibit = 250;
while ((ibit) >= 0)
{
ibit = isStream.read();
sosStream.write(ibit);
}

}
catch (IOException e)
{
out.println(e);
}
sosStream.flush();
sosStream.close();
isStream.close();
%>

</body>
</html>
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Mohan,
The following link might be helpful to you..
http://forum.java.sun.com/thread.jspa?forumID=48&threadID=549705
Regards,
Kiran.
mohan cheepu
Ranch Hand

Joined: Nov 15, 2007
Posts: 49
what is methodreturnextension and methodreturninputstream ?
it shows error, how to pass the filename into binarry inputstreamm.


i didnt get.
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi Mohan,

methodreturnextension() is the extension of the file that you need to save it.
methodreturninputstream() is the method where in which you need to convert your file contents to binary stream.

You need to understand how they have implemented in their scenario and try to implement the same in your scenario.
Check in google and be patient on the way to crack the solution.

Regards,
Kiran.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
One source of problems might be that you misspelled the Content-Disposition header value. It's called "attachment", not "attachement".

But if you want to display files in the browser you should use "inline" instead. Note that the user may have set the browser to not open certain file types, and save them to disk instead. There's nothing the web app can do about that.

Furthermore, streaming files from a JSP page is bound to cause problems, because JSPs are meant for outputting text, not binary data. You should use a servlet instead.
[ May 21, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ulf Dittmer:

Furthermore, streaming files from a JSP page is bound to cause problems, because JSPs are meant for outputting text, not binary data. You should use a servlet instead.


Specifically, the JSP compiler injects its own whitespace characters into the output stream which almost always causes the downloaded file to be corrupt.
We have an demo project in our CodeBarn that streams files from a servlet.
See:
http://faq.javaranch.com/java/CodeBarnSimpleStream


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display the allformat files on the browser using jsp or servlets