ckeditor和ueditor那个好 CKEditor和UEditor使用比较(ckeditor编辑器模糊)难以置信

随心笔谈2年前发布 编辑
184 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买


//CkeditorUploadAction类源码
public class CkeditorUploadAction extends ActionSupport {

private static final long serialVersionUID=1L;
private File upload;
private String uploadContentType;
private String uploadFileName;
//文件大小
private long fileSize;
//取文件路径
private String fileType;

public String getFileType() {
return fileType;
}

public void setFileType(String fileType) {
this.fileType=fileType;
}

public long getFileSize() {
return fileSize;
}

public void setFileSize(long fileSize) {
this.fileSize=fileSize;
}

public File getUpload() {
return upload;
}

public void setUpload(File upload) {

this.upload=upload;
}

public String getUploadContentType() {
return uploadContentType;
}

public void setUploadContentType(String uploadContentType) {
this.uploadContentType=uploadContentType;
}

public String getUploadFileName() {
return uploadFileName;
}

public void setUploadFileName(String uploadFileName) {
this.uploadFileName=uploadFileName; }

public String execute() throws Exception {
try {
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType(“text/html;charset=UTF-8”);
PrintWriter out=response.getWriter();

String callback=ServletActionContext.getRequest().getParameter(“CKEditorFuncNum”);
//对文件进行校验
if(upload==null || uploadContentType==null || uploadFileName==null){
//out.print(“<font color=”red” size=”2″>*请选择上传文件</font>”);
String path=””;
String alt_msg=”*请选择上传文件”;
out.print(“<script type=’text/javascript’>window.parent.CKEDITOR.tools.callFunction(”
+ callback
+ “, ‘”
+ path
+ “‘ , ‘”
+ alt_msg
+ “‘);</script>”);
return null;
}
if ((uploadContentType.equals(“image/pjpeg”) || uploadContentType.equals(“image/jpeg”)) && (uploadFileName.substring(uploadFileName.length() – 4).toLowerCase().equals(“.jpg”)||uploadFileName.substring(uploadFileName.length() – 5).toLowerCase().equals(“.jpeg”))) {
//IE6上传jpg图片的headimageContentType是image/pjpeg,而IE9以及火狐上传的jpg图片是image/jpeg
}else if((uploadContentType.equals(“image/x-png”) || uploadContentType.equals(“image/png”)) && uploadFileName.substring(uploadFileName.length() – 4).toLowerCase().equals(“.png”)){

}else if(uploadContentType.equals(“image/gif”) && uploadFileName.substring(uploadFileName.length() – 4).toLowerCase().equals(“.gif”)){

}else if(uploadContentType.equals(“image/bmp”) && uploadFileName.substring(uploadFileName.length() – 4).toLowerCase().equals(“.bmp”)){

}else{
//out.print(“<script language=”javascript”>alert(“*文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)”);return false;</script>”);
String path=””;
String alt_msg=”*请选择图片文件格式(必须为.jpg/.jpeg/.gif/.bmp/.png文件)”;
out.print(“<script type=’text/javascript’>window.parent.CKEDITOR.tools.callFunction(”
+ callback
+ “, ‘”
+ path
+ “‘ , ‘”
+ alt_msg
+ “‘);</script>”);

return null;
}

if(upload.length() > this.getFileSize()){
//out.print(“<font color=”red” size=”2″>*文件大小不得大于”+this.getFileSize()/(1000*1024)+”m</font>”);
String path=””;
String alt_msg=”*请选择上传”+this.getFileSize()/(1000*1024)+”M以内的图片文件”;
out.print(“<script type=’text/javascript’>window.parent.CKEDITOR.tools.callFunction(”
+ callback
+ “, ‘”
+ path
+ “‘ , ‘”
+ alt_msg
+ “‘);</script>”);
return null;
}
String imagePath=””;

//imagePath路径的设置
WebApplicationContext wac=ContextLoader.getCurrentWebApplicationContext();
WxConfig wxConfig=(WxConfig)wac.getBean(“wxConfig”);
//if(fileType.equals(PubParaConstants.DC_CK_UPLOAD_PATTH_PARAM.DC_CK_UPLOAD_PATTH_PARAM_PROSELECT)) {
imagePath=wxConfig.getFilePath();
//}
//WxConfig wxConfig;
File directory=new File(imagePath);
if(!directory.isDirectory()) {
directory.mkdirs();
}
//将文件保存到项目目录下
InputStream is=new FileInputStream(upload);
Date date=new Date(); // 获得系统时间,用于生成文件名
long lTime=date.getTime();
String fileName=DateUtil.toStringNoInterval(date, 8)+”_”+lTime;
fileName +=FileUtil.getFileSuffix(uploadFileName);
File toFile=new File(imagePath, fileName);
OutputStream os=new FileOutputStream(toFile);
byte[] buffer=new byte[1024];
int length=0;
while ((length=is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();

//设置返回“图像”选项卡

String callbackUrl=ServletActionContext.getRequest().getContextPath() +”/fckImageReader.servlet?fold=”+this.getFileType()+”&imageName=”+fileName;
out.println(“<script type=”text/javascript”>”);
out.println(“window.parent.CKEDITOR.tools.callFunction(” + callback + “,'”+ callbackUrl + “‘,”)”);
out.println(“</script>”);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

}

© 版权声明

相关文章