dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: File download on clicking the link

  1. #1
    Join Date
    Dec 2005
    Posts
    3

    File download on clicking the link

    What i need, is when the user clicks on the link to download the file it opens up the standard file save as / open dialog box. I tried using the Content Disposition method of doing it as specified in previous posts but it prompts the save as dialog box as soon as the page loads. I don't want to do that way. i want the dailog box to appear only on clicking the <a href> link.My servlet code which writes out the html is given below. pleaselet me know how can this be done?

    package JRclient;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;

    public class totalnorm_zoom extends HttpServlet{
    Rconnection c;
    public void doGet(HttpServletRequest request,HttpServletResponse response)
    throws ServletException, IOException
    {
    try{
    c=new Rconnection();
    c.voidEval("data<-read.table(\"table50.txt\",header=TRUE,sep=\"\t\")");
    c.voidEval("totnorm<-function(x,y){scale<-sum(x)/sum(y);xlab<-colnames(x);ylab<-colnames(y);x1<-x[[1]];y1<-scale*y[[1]];plot(x1,y1,xlab=xlab,ylab=ylab,col=6,col.lab=4);}");
    c.voidEval("jpeg(\"plot.jpg\")");
    String param1=request.getParameter("row");
    String param2=request.getParameter("col");
    int row=Integer.valueOf(param1).intValue();
    int col=Integer.valueOf(param2).intValue();
    c.voidEval("totnorm(data["+row+"],data["+col+"])");
    c.voidEval("dev.off()");
    c.close();
    PrintWriter out=response.getWriter();
    response.setContentType("text/html");

    out.println("<html><head></head><body><form><img src=\"C:\\Program Files\\R\\rw2011\\bin\\plot.jpg\">"+"<center><a href=\"http://localhost/R/rw2011/bin/plot.jpg\">Save</a></form></body></html>");
    out.close();
    }
    catch (RSrvException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

  2. #2
    Join Date
    Mar 2005
    Location
    Gilbert, AZ
    Posts
    293
    This is entirely the wrong forum. JavaScript != Java.

    That being said, your Content-Disposition header needs to be sent in the HTTP headers of the response to the request for the JPG, not the headers for the servlet you listed. You need to modify your web server to do that or you could write another servlet that sends the JPG with the additional header.

  3. #3
    Join Date
    Dec 2005
    Posts
    3
    Sorry about the wrong forum.

    Can you expalin in a more detailed way how this can be done. I don't know how to modify the web server, so i guess the second option of using another servlet is better in my case.

  4. #4
    Join Date
    Dec 2005
    Posts
    3
    hey thanks, i wrote the servlet and it's working fine. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles