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