indexjsp 页面代码 <%@ page language=java contentType=text/html; charset=UTF pageEncoding=UTF%><%@ page import=comckeditorCKEditorConfig %><%@ page import=javautil* %><%@ taglib uri= prefix=ckeditor%><!DOCTYPE html PUBLIC //WC//DTD HTML Transitional//EN ><html><head><meta httpequiv=ContentType content=text/html; charset=UTF><link type=text/css rel=stylesheet href=ckeditor/_samples/samplecss /><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 = requestgetParameter(editor)==null?:requestgetAttribute(editor)toString() Map<String String> attr = new HashMap<String String>() attrput(rows ) attrput(cols ) CKEditorConfig settings = new CKEditorConfig() //settingsaddConfigValue(width ) settingsaddConfigValue(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() settingsaddConfigValue(filebrowserImageUploadUrl imageUploadaction?type=Image)//上传图片 /* settingsaddConfigValue(filebrowserUploadUrl imageUploadaction?type=File)// 上传文件 settingsaddConfigValue(filebrowserFlashUploadUrl imageUploadaction?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 = ActionContextgetContext() HttpServletRequest request = (HttpServletRequest) contextget(ServletActionContextHTTP_REQUEST) HttpServletResponse response = (HttpServletResponse) contextget(ServletActionContextHTTP_RESPONSE) String fileUrl = null; String CKEditorFuncNum = requestgetParameter(CKEditorFuncNum) String scheme = requestgetScheme() int port = requestgetServerPort() String serverName = requestgetServerName() String contextPath = requestgetContextPath() /*重命名文件名称*/ Calendar cal = CalendargetInstance() SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmssSSS) String type = uploadFileNamesubstring(uploadFileNamelastIndexOf()) String newFileName = sdfformat(calgetTime()) + type; String path = requestgetSession()getServletContext()getRealPath(/) File destFile = new File(path + UPLOAD_PATH + / + newFileName) pyFile(upload destFile) (上传图片成功) fileUrl = UPLOAD_PATH + newFileName; responsesetContentType(text/html;charset=UTF) PrintWriter out = responsegetWriter() out = responsegetWriter() fileUrl = scheme + :// + serverName+:+ port + contextPath + fileUrl; (fileUrl: + fileUrl) outwrite(<script type=text/javascript>windowparentCKEDITORtoolscallFunction( + CKEditorFuncNum + + fileUrl + )</script>) outflush() outclose() } else { (未上传任何文件) } return SUCCESS; } |