• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
"attachment; filename=" +
report + ".csv" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
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;
if (bis != null)
if (bos != null)
</servlet code>
thanks in advance
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic