码迷,mamicode.com
首页 > 其他好文 > 详细

wangeditor 粘贴word内容带样式

时间:2019-10-12 19:09:21      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:web   -o   tip   图片上传   dtd   lxml   rod   head   back   

这种方法是servlet,编写好在web.xml里配置servlet-class和servlet-mapping即可使用

后台(服务端)java服务代码:(上传至ROOT/lqxcPics文件夹下)

<%@page language="java"import="java.util.*" pageEncoding="utf-8"%><%@

     page contentType="text/html;charset=utf-8"%><%@

     page import = "Xproer.*" %><%@

     page import="org.apache.commons.lang.StringUtils" %><%@

     page import="org.apache.commons.fileupload.*" %><%@

     page import="org.apache.commons.fileupload.disk.*" %><%@

     page import="org.apache.commons.fileupload.servlet.*" %><%

boolean isMultipart = ServletFileUpload.isMultipartContent(request);

FileItemFactory factory = new DiskFileItemFactory();  

ServletFileUpload upload = new ServletFileUpload(factory);

List files = null;

try

{

     files = upload.parseRequest(request);

}

catch (FileUploadException e)

{

    out.println("上传文件异常:"+e.toString());

    return;

}


FileItem imgFile = null;

Iterator fileItr = files.iterator();

while (fileItr.hasNext())

{

     imgFile = (FileItem) fileItr.next();

     if(imgFile.isFormField())

     {

         String fn = imgFile.getFieldName();

         String fv = imgFile.getString();

         if(fn.equals("uname")) uname = fv;

         if(fn.equals("upass")) upass = fv;

     }

     else

     {

         break;

     }

}

Uploader up = new Uploader(pageContext,request);

up.SaveFile(imgFile);

String url = up.GetFilePathRel();

out.write(url);

response.setHeader("Content-Length",url.length()+"");

%>


配置web.xml

 <?xmlversion="1.0"encoding="UTF-8"?>

<web-appversion="2.5"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>


前端(页面)测试代码:

<!DOCTYPEhtml PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

     <metahttp-equiv="Content-Type" content="text/html;charset=utf-8"/>

     <title>WordPaster-jsp-ueditor-1.2.6.0</title>

     <scripttype="text/javascript" src="ueditor.config.js" charset="utf-8"></script>

     <scripttype="text/javascript" src="ueditor.all.min.js" charset="utf-8"></script>

     <linktype="text/css" rel="Stylesheet" href="WordPaster/css/WordPaster.css"/>

    <linktype="text/css" rel="Stylesheet" href="WordPaster/js/skygqbox.css" />

    <scripttype="text/javascript" src="WordPaster/js/json2.min.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/jquery-1.4.min.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/w.edge.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/w.app.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/w.file.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/skygqbox.js" charset="utf-8"></script>

    <scripttype="text/javascript" src="WordPaster/js/WordPaster.js" charset="utf-8"></script>

</head>

<body>

     <textareaname="后台取值的key"id="myEditor">这里写你的初始化内容</textarea>

     <scripttype="text/javascript">

        var pasterMgr = new WordPasterManager();

        //pasterMgr.Config["PostUrl"] = "http://www.ncmem.com/products/upload_ori.aspx"

    pasterMgr.Config["PostUrl"] = "http://localhost:8080/WordPaster2UEditor1.4x/upload.jsp"

    //pasterMgr.Config["PostUrl"] = "http://cloud.dyso.cn/ueditor/upload.jsp"

    pasterMgr.Load();//加载控件


        var ue = UE.getEditor(‘myEditor‘);

        

         ue.ready(function() {

             //设置编辑器的内容

             ue.setContent(‘hello‘);

             //获取html内容,返回: <p>hello</p>

             var html = ue.getContent();

             //获取纯文本内容,返回: hello

             var txt = ue.getContentTxt();

             pasterMgr.SetEditor(ue);

         });

                  

     </script>

</body>

</html>

实现后的效果,能够批量上传word中的全部图片,大幅度提升图片上传效率。而且能够保留Word样式。

 

技术图片技术图片

图片上传完后,编辑器里面的图片地址也全部都改成了服务器的图片地址了,

技术图片技术图片

 

详细配置信息可以参考这篇文章:http://blog.ncmem.com/wordpress/2019/10/12/wangeditor-%e7%b2%98%e8%b4%b4word%e5%86%85%e5%ae%b9%e5%b8%a6%e6%a0%b7%e5%bc%8f/

wangeditor 粘贴word内容带样式

标签:web   -o   tip   图片上传   dtd   lxml   rod   head   back   

原文地址:https://www.cnblogs.com/songsu/p/11663190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!