ckeditor后台保存为html和doc

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文档编辑</title>


<!-- ckeditor配置文件为/js/ckeditor/config.js -->
<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>

</head>
<body>
    <!-- 指定method=post可防止编辑内容乱码 -->
	<form id="detail" action="edithandler" method="post">
		<table>
			<tr>
				<td><label><b>文档内容编辑:</b></label><br>
					<hr> <textarea rows="50" cols="50" name="editor01"></textarea>
				</td>
			</tr>
		</table>
		<hr>
		<input type="submit" value="保存">
	</form>
	<script type="text/javascript">
		var p_desc = CKEDITOR.replace('editor01');
		function showEditorContent() {
			var title = document.getElementByName("documentName").value;
			alert(title);
		}
		function showEditorNo() {
			var title = document.getElementById("publishNumber").value;
			alert(title);
		}
	</script>
</body>
</html>

以上是编辑页面

form请求传送至editHandler

在Controller里增加对请求的响应

	@RequestMapping("/edithandler")
	public String getEditorHandler(HttpServletRequest request) {

		String documentName = request.getParameter("documentName");
		String content = request.getParameter("editor01");
		String storePath = "/home/hdpuser1/runkelaw/fortest/files/";
		this.documentService.storeDocument(documentName,content,storePath);
		return "internal/editor/editResult";
	}

StoreDocumentImpl里的storeDocument方法

	@Override
	public boolean storeDocument(String documentName, String content,
			String storePath) {

		try {
			String head = "<html><head><meta charset=\"utf-8\" /></head><body>";
			String tail = "</body></html>";
			
			System.out.println(content);
			content = head + content + tail;
			System.out.println(content);
			FileWriter writer = new FileWriter(storePath + documentName
					+ ".html", true);
			writer.write(content);
			writer.close();
			
			System.out.println("************************************the content of the ckeditor:");
			System.out.println(content);



		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		try {
			
			String head="<html><head></head><body>";
			String tail="</body></html>";
			content=head+content+tail;
			byte b[]=content.getBytes("UTF-8");
			ByteArrayInputStream bais = new ByteArrayInputStream(b);
			POIFSFileSystem poifs = new POIFSFileSystem();
			DirectoryEntry directory = poifs.getRoot();
			DocumentEntry documentEntry = directory.createDocument(
					"WordDocument", bais);
			FileOutputStream ostream = new FileOutputStream(storePath + documentName + ".doc");
			poifs.writeFilesystem(ostream);
			bais.close();
			ostream.close();

		} catch (IOException e) {
			e.printStackTrace();
		}

		return true;
	}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值