首先关于触发事件应该a标签事件
var url=“http://www.w3school.com.cn/tags/att_a_target.asp”;
var a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("target", "_blank");
a.setAttribute("id", "openwin");
document.body.appendChild(a);
a.click();
这个是前台调用的地方后台代码简单主要运用输入输出流
@RequestMapping(params = "actionMethod=getHelpPdf")
public void getHelpPdf(HttpServletRequest request,HttpServletResponse response, Model model) throws Exception {
String filePath = Parameter.getInstance().getProp().getProperty("helpPath")+"help.pdf";
String helpName = Parameter.getInstance().getProp().getProperty("helpName");
String filename = helpName+" .pdf";
if (null != filename) {
filename = filename.trim();
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;fileName=" + filename);
String agent = request.getHeader("USER-AGENT").toLowerCase();
String codedFileName = java.net.URLEncoder.encode(filename, "UTF-8");
if (agent.contains("firefox")) {
response.setHeader("Content-Disposition", "attachment; filename="
+ new String(filename.getBytes("gb2312"), "ISO8859-1"));
} else {
response.setHeader("content-disposition", "attachment;filename="
+ codedFileName);
}
try {
File file = new File(filePath);
System.out.println(file.getAbsolutePath());
InputStream inputStream = new FileInputStream(file);
OutputStream os = response.getOutputStream();
byte[] b = new byte[1024];
int length;
while ((length = inputStream.read(b)) > 0) {
os.write(b, 0, length);
}
os.flush();
os.close();
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}