直接上代码
前台:
<iframe id='medicalRecordHTML' frameborder='0' src='xxx' style='width:100%;height:100%;' ></iframe>
后台:
try {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html; charset=utf-8");
OutputStream out = response.getOutputStream();
String outHtml=medicalRecordService.findOneMedicalRecord(dto);
String webRoot=ServletActionContext.getRequest().getContextPath();
Pattern p = Pattern.compile("html\\.css");
Matcher m = p.matcher(outHtml);
if(m.find()){
String temp = outHtml.substring(m.start(),m.end());
outHtml = outHtml.replaceAll(temp,"\\"+webRoot+"\\/css\\/html\\.css" );
}
out.write(outHtml.getBytes());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
虽然运行后台会抛错误,但是不影响功能。