当我们前端使用ueditor插件来让用户输入数据,保存至数据库。在另一个地方需要打印用户输入的内容的时候可以用到。因为要将ueditor带格式保存下来保存的就是html格式的内容,后台转化如下:

      @RequestMapping("ueditorPrintAction.do")
public void uePrint(HttpServletRequest request,HttpServletResponse response) throws IOException{
CivilParam param=new CivilParam();
param.setParamData(null);
CivilResult result=ueditorPrintService.queryContext(param);
map=(Map) result.getResultData();
//以上是通过pring dubbo来进行数据库查询
String htmlContent=map.get("content").toString();
//字符替换
htmlContent = htmlContent.replaceAll("`lt`", "<");
htmlContent = htmlContent.replaceAll("`gt`", ">");
htmlContent = htmlContent.replaceAll("`quot`", "\"");
htmlContent = htmlContent.replaceAll("`#39`", "'"); String content = "<html>"+htmlContent+"</html>";
//如果出现乱码getBytes传入编码参数
byte b[] = content.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
//输出文件 名
String name=map.get("name").toString();
//如何出现乱码getBytes传入编码参数
// HttpServletResponse response = getResponse();
response.setHeader("Content-Disposition",
"attachment;filename=" +
new String( (name + ".doc").getBytes(),
"iso-8859-1"));
response.setContentType("application/msword");
OutputStream ostream = response.getOutputStream();
poifs.writeFilesystem(ostream);
//return JSON;
}

最新文章

  1. Linux内核补丁升级
  2. Windows Server 2003开机自动启动MySQL服务设置方法
  3. SQL Server 2008R2 禁用远程连接
  4. Content Providers
  5. DUBBO安装配置注意事项
  6. $(document).ready(); $().ready(); $()
  7. 升级python的sqlite库版本
  8. Spark1.5.1的安装与部署 每一步详细测试截图
  9. [转]解决get方法传递URL参数中文乱码问题
  10. cocos2d之Box2D详细说明 鼠标联合实现
  11. STM32F4中USB与PC双向通信
  12. 购物网站首页(学习ING)
  13. 如何使用Shiro
  14. JS闭包与JS函数
  15. 基于Winform框架DataGridView控件的SqlServer数据库查询展示功能的实现
  16. Ansible 进阶技巧
  17. Python threading 单线程 timer重复调用函数
  18. 富文本(wangEditor框架)的使用教程
  19. spring---aop(9)---Spring AOP中引入增强
  20. Vue项目中将table组件导出Excel表格以及打印页面内容

热门文章

  1. Airtest多设备跑
  2. 解决phpstudy mysql 启动不了的问题
  3. 如何分页爬取数据--beautisoup
  4. jQuery样式操作
  5. jmeter实现逻辑控制器
  6. nyoj124-中位数
  7. js生产随机数
  8. python 协程 greenlet gevent
  9. InfoSYS-20170114
  10. 02018_StringBuffer练习