打印pdf文件 在tomcat下正常 部署到jboss下就出问题?
/**
* 转换PDF功能
* @throws Exception
* @throws DocumentException
*/
@SuppressWarnings("unchecked")
public void print() throws Exception,DocumentException {
// 获取packageId 并保存至session
String packageId = Struts2Util.getRequest().getParameter("packageId");
Struts2Util.getSession().setAttribute("packageId", packageId);
// covert pdf
HttpURLConnection con = null;
URL url = null;
try
{
String sessionid = Struts2Util.getRequest().getSession().getId();
url = new URL("http://127.0.0.1:8080/scm/shipments!viewPackingSlip.action");
//url = new URL("http://10.168.2.182:8080/scm/shipments!viewPackingSlip.action");
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Cookie","JSESSIONID="+sessionid);
con.connect();
int size = 0;
byte[] buf = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
StringBuffer sb = new StringBuffer();
while ((size = bis.read(buf)) != -1)
{
sb.append(new String(buf, 0, size));
}
System.out.println(sb.toString());
bis.close();
con.disconnect();
HttpServletResponse response = Struts2Util.getResponse();
response.setContentType("APPLICATION/DOWNLOAD");
response.setHeader("Content-Disposition", "attachment; filename="+ "PackingSlip.pdf");// PackingSlip是文件名
java.io.OutputStream os = response.getOutputStream();
List headerFooterList = new ArrayList();
Map properties = new HashMap();
CYaHPConverter converter = new CYaHPConverter();
String ss = "http://127.0.0.1:8080/scm/stylesheet/";
//String ss = "http://10.168.2.182:8080/scm/stylesheet/";
converter.convertToPdf(sb.toString(), IHtmlToPdfTransformer.A4P,headerFooterList, ss, os, properties);
System.out.print("Converter Success!");
os.flush();
os.close();
response.flushBuffer();
}catch (IOException e)
{ }
}