<%@ 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;
}