This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet downloads Excel file ok but also attempts Servlet & JSP files !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet downloads Excel file ok but also attempts Servlet & JSP files !! " Watch "Servlet downloads Excel file ok but also attempts Servlet & JSP files !! " New topic
Author

Servlet downloads Excel file ok but also attempts Servlet & JSP files !!

Kop Ite
Greenhorn

Joined: Aug 06, 2001
Posts: 9
Hi,
My Servlet code downloads a csv into Excel as required BUT it also attempts to download the JSP file (that calls the servlet) and the Servlet file as well.... How do I ensure that only the csv file is downloaded. I am using the following code.
<servlet code>
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream ();
res.setContentType( "application/vnd.ms-excel" );
String report = req.getParameter("report");
filename = report + user_id + ".csv";
String fileURL = the url;
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Content-disposition",
"attachment; filename=" +
report + ".csv" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL ( fileURL );
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
}
catch(final MalformedURLException e)
{
System.out.println ( "MalformedURLException." );
throw e;
}
catch(final IOException e)
{
System.out.println ( "IOException." );
throw e;
}
finally
{
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
</servlet code>
thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet downloads Excel file ok but also attempts Servlet & JSP files !!
 
Similar Threads
How to Return a File using Servlet
setting name of requested pdf in browser's title
error outputting a pdf file
Generating PDF and displaying it ...
displaying pdf file