indexjsp 頁面代碼 <%@ page language=
java
contentType=
text/html; charset=UTF
pageEncoding=
UTF
%><%@ page import=
com
ckeditor
CKEditorConfig
%><%@ page import=
java
util
*
%><%@ taglib uri=
prefix=
ckeditor
%><!DOCTYPE html PUBLIC
//W
C//DTD HTML
Transitional//EN
><html><head><meta http
equiv=
Content
Type
content=
text/html; charset=UTF
><link type=
text/css
rel=
stylesheet
href=
ckeditor/_samples/sample
css
/><title>CKEditor Demo</title></head><body><form action=
CKEditor
method=
post
>
<p>
<label for=
editor
>Editor
:</label>
<textarea cols=
id=
editor
name=
editor
rows=
></textarea>
</p>
<p>
<label for=
editor
>Editor
:</label>
<%
//String value =
My first <strong>CKEditor</strong> Java tag
;
String value = request
getParameter(
editor
)==null?
:request
getAttribute(
editor
)
toString()
Map<String
String> attr = new HashMap<String
String>()
attr
put(
rows
)
attr
put(
cols
)
CKEditorConfig settings
= new CKEditorConfig()
//settings
addConfigValue(
width
)
settings
addConfigValue(
toolbar
Basic
)
%>
<ckeditor:editor basePath=
ckeditor/
textareaAttributes=
<%=attr %>
config=
<%=settings
%>
editor=
editor
value=
<%= value %>
/>
</p>
<p><input type=
submit
value=
Submit
/></p></form><%
CKEditorConfig settings = new CKEditorConfig()
settings
addConfigValue(
filebrowserImageUploadUrl
imageUpload
action?type=Image
)
//上傳圖片
/*
settings
addConfigValue(
filebrowserUploadUrl
imageUpload
action?type=File
)
// 上傳文件
settings
addConfigValue(
filebrowserFlashUploadUrl
imageUpload
action?type=Flash
)
//上傳flash
*/%><ckeditor:replace replace=
editor
basePath=
ckeditor/
config=
<%=settings %>
/></body></html>
圖片上傳action主要代碼 public String execute() throws Exception {
(
upload image…
)
if(upload != null) {
ActionContext context = ActionContext
getContext()
HttpServletRequest request = (HttpServletRequest) context
get(ServletActionContext
HTTP_REQUEST)
HttpServletResponse response = (HttpServletResponse) context
get(ServletActionContext
HTTP_RESPONSE)
String fileUrl = null;
String CKEditorFuncNum = request
getParameter(
CKEditorFuncNum
)
String scheme = request
getScheme()
int port = request
getServerPort()
String serverName = request
getServerName()
String contextPath = request
getContextPath()
/*重命名文件名稱*/
Calendar cal = Calendar
getInstance()
SimpleDateFormat sdf = new SimpleDateFormat(
yyyyMMddHHmmssSSS
)
String type = uploadFileName
substring(uploadFileName
lastIndexOf(
))
String newFileName = sdf
format(cal
getTime()) + type;
String path = request
getSession()
getServletContext()
getRealPath(
/
)
File destFile = new File(path + UPLOAD_PATH +
/
+ newFileName)
pyFile(upload
destFile)
(
上傳圖片成功
)
fileUrl = UPLOAD_PATH + newFileName;
response
setContentType(
text/html;charset=UTF
)
PrintWriter out = response
getWriter()
out = response
getWriter()
fileUrl = scheme +
://
+ serverName+
:
+ port + contextPath + fileUrl;
(
fileUrl:
+ fileUrl)
out
write(
<script type=
text/javascript
>window
parent
CKEDITOR
tools
callFunction(
+ CKEditorFuncNum +
+ fileUrl +
)
</script>
)
out
flush()
out
close()
} else {
(
未上傳任何文件
)
}
return SUCCESS;
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26561.html