Question : Building a URL for a Servlet generated file

I have a Servlet that creates a CVS file based on some user specifications. The file is created but it is created on my weblogic domain root (user_projects/domain/mydomain)

The issue is that after I created the file I need to provide an URL for the user to download the file, since the deployment is on a WAR file it is not clear for me where should I store the CSV file for been able to provide a URL to the user.

Answer : Building a URL for a Servlet generated file

example:


public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,  IOException{
     if(request.getParameter("download")!=null){
     InputStream in =generateCSVFile(request);
     response.setContentType("application/csv");
     OutputStream out=response.getOutputStream();
     int k=-1;
     byte[] buf = new byte[10000];
     while((k=in.read(buf)) >0){
        out.write(buf,0,k);
     }
     }else{
         response.getOutputWriter().write("ml> .... Download csv ...");
     }
 
}
Random Solutions  
 
programming4us programming4us