在跳出的dialog中使用kindeditor
jsp:
父jsp:
<td valign="top" align="right"><span style="font-size:12px;">公告详细信息:</span></td>
<td valign="top" align="left">
<span style="font-size:12px;">
<a class="easyui-linkbutton" οnclick="contentEditor()">编辑详细信息</a>
<input name="noticeContentStr" id="noticeContentStr" type="hidden" ></input>
</span>
</td>
父js:
//kindEditor新增方法 function GetData(data){ $("#addForm #noticeContentStr").val(data); }
子jsp及js:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
String id = request.getParameter("id");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>公告详细内容</title>
<link rel="stylesheet" href="<%=basePath%>kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=basePath%>kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="<%=basePath%>kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="<%=basePath%>kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=basePath%>kindeditor/plugins/code/prettify.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<script>
var editor1;
var id = '<%=id%>';
var self ;
KindEditor.ready(function(K) {
editor1 = K.create('textarea[name="content1"]', {
uploadJson :'<%=basePath%>/Upload_json',
fileManagerJson :'<%=basePath%>/File_manager_json',
allowFileManager : true,
afterCreate : function() {
self = this;
//根据id用ajax 如果id不等于 0 进行操作 用getNotices方法 取NoticesContentStr,如果id=0 NoticesContentStr=null
if(id!=null && id !=''){
K.ajax('<%=basePath%>notice/getNotice.do?id='+id, function(data) {
console.log(data);
self.html(data.data);
}, 'POST', {
});
}
}
});
prettyPrint();
});
//function clearInput(){
//清空KindEditor
//KindEditor.instances[0].html(""); //0表示第一个KindEditor编辑器对象
//}
//传送html到notice.jsp
function saveNew() {
var data=editor1.html();
parent.GetData(data);
}
function save(){
var data=editor1.html();
console.log(data);
KindEditor.ajax('<%=basePath%>/notice/upt.do', function(data) {
}, 'POST', {
id:id,
NoticeContentStr:data
});
}
</script>
</head>
<body>
<form id="example" method="post" >
<textarea name="content1" id="content1" cols="60" rows="8" style="width:100%;height:350px;visibility:hidden;"></textarea>
<input type="button" name="aa" id="aa" οnclick="save()" value="提交" style="visibility:hidden;"/>
<input type="button" name="aaNew" id="aaNew" οnclick="saveNew()" value="提交" style="visibility:hidden;"/>
</form>
</body>
</html>
servelt:根据kindeditor文件中jsp文件下的2个jsp,写5个servelt;
1.File_manager_json.java,先在webapp下创建attached文件夹
2.NameComparator.java
3.SizeComparator.java
4.TypeComparator.java
5.Upload_json.java