社区
Java EE
帖子详情
TinyMCE中如何实现图片上传的功能?
orical1234
2009-05-11 09:45:08
急~ 如何在TinyMCE中实现图片上传的功能?应用于java的有没有啊?谢谢
...全文
2398
2
打赏
收藏
TinyMCE中如何实现图片上传的功能?
急~ 如何在TinyMCE中实现图片上传的功能?应用于java的有没有啊?谢谢
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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
实现
本地
图片上传
在本教程
中
,我们将深入探讨如何在
TinyMCE
中
实现
本地
图片上传
功能
。 首先,你需要在项目
中
引入
TinyMCE
。这通常通过下载其源码或通过CDN链接完成。一旦引入,你需要配置
TinyMCE
,指定一个容器元素,以及所需的工具栏...
TinyMCE
自定义上传图片
在这个场景
中
,我们将重点讨论如何在
TinyMCE
中
实现
自定义
图片上传
功能
。 首先,我们需要理解
TinyMCE
的插件系统。
TinyMCE
的插件是可插入到编辑器
中
的独立
功能
模块,它们通常包含JavaScript代码,用于扩展编辑器的...
tinymce
自定义多图片批量上传插件 附使用示范Test
5. **
图片上传
后处理**:在
图片上传
到服务器并返回URL后,我们需要将这些URL插入到
TinyMCE
编辑器
中
。可以使用`editor.insertContent`方法来
实现
: ```javascript function insertImages(imgUrls) { for (var i = ...
tinyMCE
本地图片预览
###
tinyMCE
本地图片预览
实现
详解 #### 一、简介
tinyMCE
是一款非常流行的开源富...通过上述步骤和技术细节,我们可以有效地
实现
在
tinyMCE
中
本地预览图片的
功能
,这对于提高用户的编辑体验和工作效率具有重要意义。
TinyMce
上传多图片组件(修改).zip
在这个"
TinyMce
上传多图片组件(修改).zip"压缩包
中
,我们关注的是它的一个增强
功能
,即支持多
图片上传
。这在内容创作,尤其是需要大量配图的博客或文章编辑
中
,是非常实用的
功能
。 首先,我们要理解
TinyMce
的...
Java EE
67,543
社区成员
225,859
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章