社区
Java EE
帖子详情
TinyMCE中如何实现图片上传的功能?
orical1234
2009-05-11 09:45:08
急~ 如何在TinyMCE中实现图片上传的功能?应用于java的有没有啊?谢谢
...全文
2386
2
打赏
收藏
TinyMCE中如何实现图片上传的功能?
急~ 如何在TinyMCE中实现图片上传的功能?应用于java的有没有啊?谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
orical1234
2009-05-11
打赏
举报
回复
谢谢~但是公司里不让用struts。只能用spring,请问还有其他办法吗?
凌霞君
2009-05-11
打赏
举报
回复
为tinyMCE增加图片上传功能
本实现采用Struts实现图片的上传。 步骤如下:
1.编写文件上传类。代码清单如下:
FileUploadAction.java代码清单如下:
package com.family.fileupload.web.action; import java.util.Calendar; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import com.family.fileupload.web.form.FileUploadForm; import com.family.fileupload.web.utils.FileUpload; public class FileUploadAction extends DispatchAction { public ActionForward uploadImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { FileUploadForm uploadForm = (FileUploadForm) form; FileUpload fu = new FileUpload(uploadForm.getFile()); String realPath = this.getRealPath("/pictures"); String fileName = this.getFileKeyRule() + "." + fu.getExtendName().toLowerCase(); String filePath = realPath + "/" + fileName; fu.saveToFile(filePath); request.setAttribute("fileUrl", this.getRootUrl(request) + "/pictures/" + fileName); return mapping.findForward("image.success"); } private String getRootUrl(HttpServletRequest request) { StringBuffer buf = request.getRequestURL(); int length = request.getRequestURI().length(); buf.delete(buf.length() - length, buf.length()); return buf.toString(); } private String getRealPath(String floder) { return this.getServlet().getServletConfig().getServletContext().getRealPath(floder); } private String getFileKeyRule() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); int iYear = cal.get(Calendar.YEAR); int iMonth = cal.get(Calendar.MONDAY) + 1; int iDay = cal.get(Calendar.DAY_OF_MONTH); int iHour = cal.get(Calendar.HOUR_OF_DAY); int iMinute = cal.get(Calendar.MINUTE); int iSecond = cal.get(Calendar.SECOND); StringBuffer strKey = new StringBuffer(15); strKey.append(iYear); if (iMonth < 10) { strKey.insert(4, '0'); strKey.insert(5, iMonth); } else { strKey.insert(4, iMonth); } if (iDay < 10) { strKey.insert(6, '0'); strKey.insert(7, iDay); } else { strKey.insert(6, iDay); } if (iHour < 10) { strKey.insert(8, '0'); strKey.insert(9, iHour); } else { strKey.insert(8, iHour); } if (iMinute < 10) { strKey.insert(10, '0'); strKey.insert(11, iMinute); } else { strKey.insert(10, iMinute); } if (iSecond < 10) { strKey.insert(12, '0'); strKey.insert(13, iSecond); } else { strKey.insert(12, iSecond); } return strKey.toString(); } }
FileUploadForm.java代码清单如下:
package com.family.fileupload.web.form; import org.apache.struts.action.ActionForm; import org.apache.struts.upload.FormFile; public class FileUploadForm extends ActionForm { private static final long serialVersionUID = 1L; private FormFile file = null; public FormFile getFile() { return file; } public void setFile(FormFile file) { this.file = file; } }
FileUpload.java代码清单如下:
package com.family.fileupload.web.utils; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.struts.upload.FormFile; public class FileUpload { private FormFile file; private int fileSize; private String fileName; private String extendName; private String contentType; public FileUpload (FormFile file) { this.file = file; fileName = this.file.getFileName(); fileSize = this.file.getFileSize(); contentType = this.file.getContentType(); int position = this.file.getFileName().indexOf("."); extendName = this.file.getFileName().substring(position + 1, this.file.getFileName().length()); } public void saveToFile(String fileName) { try { InputStream is = this.file.getInputStream(); int bytesRead = 0; byte[] buffer = new byte[8912]; OutputStream os = new FileOutputStream(fileName); while ((bytesRead = is.read(buffer, 0, 8912)) != -1) { os.write(buffer, 0, bytesRead); } is.close(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public String getContentType() { return contentType; } public String getExtendName() { return extendName; } public FormFile getFile() { return file; } public String getFileName() { return fileName; } public int getFileSize() { return fileSize; }}
2.将以上文件编译后打包成 upload.jar,并发布到Liferay应用的包路径下({$LIFERAY_HOME}/webapps/ROOT/WEB-INF/lib);
3.编写upload.jsp并复制到liferay应用的的{$LIFERAY_HOME}/webapps/ROOT\html\js\editor\ tinymce\ plugins\advimage\目录下;
Upload.jsp的代码清单如下:
<form action="/c/portal/fileUpload?method=uploadImage" method="post" enctype="multipart/form-data"> <input type="file" name="file"> <input type="submit"> </form>
4.编写imagePath.jsp并复制到\webapps\ROOT\html下;
代码清单如下:
<script> function insertImage() { var imageUrl = '<%=(String) request.getAttribute("fileUrl")%>'; if (imageUrl != '') { opener.document.all("src").value = imageUrl; window.close(); } } </script>
5. 在tinymce.jsp中增加如下代码
*/ function fileBrowserCallBack(field_name, url, type, win) { //打开文件上传窗口 win.open("upload.jsp"); }
6. 在liferay的配置文件struts-config.xml或struts-config-ext.xml文件中增加如下配置:
增加formbean配置:
<form-beans> ...... <form-bean name="fileUploadForm" type="com.family.fileupload.web.form.FileUploadForm" /> </form-beans>
增加action配置:
<action-mappings> …… <action name="fileUploadForm" path="/portal/fileUpload" scope="request" type="com.family.fileupload.web.action.FileUploadAction" parameter="method"> <forward name="file.success" path="/filePath.jsp"/> <forward name="image.success" path="/imagePath.jsp"/> </action> </action-mappings>
http://blog.csdn.net/sumongh_pan/archive/2007/04/11/1560603.aspx
TinyMCE
+ 插件powerpaste
实现
word直接粘贴富文本,同时上传图片.zip
powperpaste现在是收费插件,官网最低售价12美元/每月,可从word直接粘贴富文本,同时上传图片
TinyMCE
新增本地
图片上传
功能
实现
思路: 使用Ajax 进行
图片上传
,此上传方式可以更友好的
实现
TinyMCE
的
图片上传
扩展, 具体方法可以参考我的上一篇 Jquery ajaxsubmit 上传图片。将Ajax上传图片集成到
TinyMCE
中
, 主要是修改
TinyMCE
目录下...
将
tinymce
编辑器移植到lotus domino平台,解决了图片附件上传的问题
1.修改了\RichEditer\iXs_Editor\plugins\advimage\editor_plugin.js的js文件以
实现
插入图片的
功能
,其他所有
功能
都在表单上。 2.用js提取了图片文件路径。然后进行处理。 3.移植的很不充分,我对这个编辑器也是...
tinymce
整合vue
tinymce
整合vue代码,
实现
视频自定义上传、图片自定义上传
功能
。整合文档可参考:https://blog.csdn.net/qq_35134375/article/details/107366909
tinymac的收费插件powerpaste
tinymce
实现
从word直接粘贴并自动上传图片 powerpaste plugin source code
Java EE
67,512
社区成员
225,885
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章