package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.UUID;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class CkeditorUploadAction extends ActionSupport {
private String uploadContentType;
private String uploadFileName;
private String CKEditorFuncNum;
private String CKEditor;
private String langCode;
private File upload;
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getCKEditorFuncNum() {
return CKEditorFuncNum;
}
public void setCKEditorFuncNum(String cKEditorFuncNum) {
CKEditorFuncNum = cKEditorFuncNum;
}
public String getCKEditor() {
return CKEditor;
}
public void setCKEditor(String cKEditor) {
CKEditor = cKEditor;
}
public String getLangCode() {
return langCode;
}
public void setLangCode(String langCode) {
this.langCode = langCode;
}
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;
}
@Override
public String execute() throws Exception {
String strUrl="";
String strPath = ServletActionContext.getServletContext().getRealPath("ckeditor/uploader/upload");
File path = new File(strPath);
if(!path.exists()){
path.mkdirs();
}
String uuid = UUID.randomUUID().toString();
String rt[] = this.getUploadFileName().split("\\.");
System.out.println(rt[1]);
uploadFileName = new String(uuid+"."+rt[1]);//解决上传中文图片、flash或含中文路径时服务器报错的问题。
String type =null;
if("jpg".equals(rt[1]) ||"png".equals(rt[1]) ||"gif".equals(rt[1]) ||"jpeg".equals(rt[1]) ||"bmp".equals(rt[1]))
{
type = "images/";
}
if("swf".equals(rt[1]))
{
type="flashs/";
}
//FileImageInputStream is = new FileImageInputStream(this.upload);
//FileImageOutputStream os = new FileImageOutputStream(new File(strPath + File.separator + this.uploadFileName));
InputStream is = new FileInputStream(this.upload);
OutputStream os = new FileOutputStream(new File(strPath + File.separator +type+ this.uploadFileName));
// System.out.println(strPath);
// System.out.println(File.separator);
try {
int len;
byte[] buffer = new byte[1024];
while ((len=is.read(buffer)) > 0) {
os.write(buffer,0,len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(is!=null){
is.close();
}
if(os!=null){
os.close();
}
}
PrintWriter out = ServletActionContext.getResponse().getWriter();
//返回给ckeditor
strUrl=strPath+ "\\" + this.uploadFileName ;
strUrl= strUrl.replace('\\', '/');//这里如果不替换,会出错!!!
// System.out.println(strUrl);
out.write("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction("+this.CKEditorFuncNum+", 'ckeditor/uploader/upload/"
+ type
+ this.uploadFileName
+ "', '');</script>");
return Action.NONE;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Ckeditor--upload-picture-struts2.zip_ckediter struts2_ckeditor_j
共369个文件
js:138个
png:78个
gif:76个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 144 浏览量
2022-09-14
20:00:44
上传
评论
收藏 4.66MB ZIP 举报
温馨提示
ckeditor编辑器在struts2中的使用 上传图片 flash 都已经实现
资源推荐
资源详情
资源评论
收起资源包目录
Ckeditor--upload-picture-struts2.zip_ckediter struts2_ckeditor_j (369个子文件)
CkeditorUploadAction.class 4KB
HibernateSessionFactory.class 2KB
editorAction.class 2KB
Texteditor.class 1KB
.classpath 741B
org.eclipse.wst.common.component 462B
org.eclipse.wst.jsdt.ui.superType.container 49B
editor.css 35KB
editor.css 35KB
editor.css 31KB
editor.css 31KB
editor.css 30KB
editor.css 30KB
dialog.css 18KB
dialog.css 18KB
dialog.css 16KB
dialog.css 16KB
dialog.css 15KB
dialog.css 15KB
yui.css 3KB
yui.css 3KB
templates.css 2KB
templates.css 2KB
templates.css 1KB
templates.css 1KB
templates.css 1KB
templates.css 1KB
toolbar.css 1KB
toolbar.css 1KB
wsc.css 1004B
wsc.css 1004B
contents.css 559B
contents.css 559B
uicolor.gif 1KB
uicolor.gif 1KB
cry_smile.gif 468B
cry_smile.gif 468B
angel_smile.gif 465B
angel_smile.gif 465B
confused_smile.gif 464B
confused_smile.gif 464B
sad_smile.gif 460B
sad_smile.gif 460B
wink_smile.gif 458B
wink_smile.gif 458B
whatchutalkingabout_smile.gif 452B
whatchutalkingabout_smile.gif 452B
omg_smile.gif 451B
omg_smile.gif 451B
regular_smile.gif 450B
regular_smile.gif 450B
shades_smile.gif 449B
shades_smile.gif 449B
tounge_smile.gif 446B
tounge_smile.gif 446B
angry_smile.gif 443B
angry_smile.gif 443B
teeth_smile.gif 442B
embaressed_smile.gif 442B
embaressed_smile.gif 442B
teeth_smile.gif 442B
devil_smile.gif 436B
devil_smile.gif 436B
envelope.gif 426B
envelope.gif 426B
template3.gif 422B
template3.gif 422B
thumbs_down.gif 408B
thumbs_down.gif 408B
thumbs_up.gif 396B
thumbs_up.gif 396B
template1.gif 375B
template1.gif 375B
lightbulb.gif 368B
lightbulb.gif 368B
template2.gif 333B
template2.gif 333B
kiss.gif 241B
kiss.gif 241B
broken_heart.gif 192B
broken_heart.gif 192B
anchor.gif 184B
anchor.gif 184B
heart.gif 183B
mini.gif 183B
mini.gif 183B
mini.gif 183B
heart.gif 183B
mini.gif 183B
mini.gif 183B
mini.gif 183B
hiddenfield.gif 105B
toolbar_start.gif 105B
toolbar_start.gif 105B
hiddenfield.gif 105B
toolbar_start.gif 105B
toolbar_start.gif 105B
placeholder.gif 96B
placeholder.gif 96B
pagebreak.gif 54B
共 369 条
- 1
- 2
- 3
- 4
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功