Set attach header for HttpServletResponse - Java javax.servlet.http

Java examples for javax.servlet.http:HttpServletResponse

Description

Set attach header for HttpServletResponse

Demo Code


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Main{
    public static void attach(HttpServletRequest request,
            HttpServletResponse response, String filename) {
        if (request.getParameter("attachment") != null) {
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + filename.replace('"', '-')
                            + "\"");
        }//from  w w  w.j  ava2 s . co  m
    }
}

Related Tutorials