/    Sign up×
Community /Pin to ProfileBookmark

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();
}
}

}

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@MongusDec 21.2005 — 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.
Copy linkTweet thisAlerts:
@VasuakkauthorDec 21.2005 — 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.
Copy linkTweet thisAlerts:
@VasuakkauthorDec 21.2005 — hey thanks, i wrote the servlet and it's working fine. Thanks!
×

Success!

Help @Vasuakk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...