java生成文档,手机与电脑查看的格式不一样

cai_jim_xiaoniu 2017-06-01 10:25:08
Configuration freemarkerCfg = new Configuration();
//加载模版
ServletContext servletContext = htmlCarrier.getRequest().getSession().getServletContext();
freemarkerCfg.setServletContextForTemplateLoading(servletContext, Constants.HTML_TEMPLATE_PATH_BASE);
freemarkerCfg.setEncoding(Locale.getDefault(), "UTF-8");
try {
//指定模版路径
Template template = freemarkerCfg.getTemplate(htmlCarrier.getTemplatePath(),"UTF-8");
template.setEncoding("UTF-8");
//静态页面路径
String htmlPath = null;
if(Constants.isOnServer){
htmlPath = Constants.SERVER_SAVEFILE_PATH+"/"+htmlCarrier.getTargetPath();
}
else {
htmlPath = servletContext.getRealPath("/")+htmlCarrier.getTargetPath();
}
File htmlFile = new File(htmlPath);
FileOutputStream fs = new FileOutputStream(htmlFile);
OutputStreamWriter os = new OutputStreamWriter(fs,"UTF-8");
Writer out = new BufferedWriter(os);
//处理模版
template.process(htmlCarrier.getData(), out);
out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}



用浏览器模拟手机运行没有问题
手机用IP测试会报错java.lang.IllegalStateException: getOutputStream() has already been called for this response
...全文
328 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cai_jim_xiaoniu 2017-08-04
  • 打赏
  • 举报
回复
没人发言吗,先到先得
cai_jim_xiaoniu 2017-07-07
  • 打赏
  • 举报
回复
没找到什么好的解决办法,只能用poi读写一遍

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧