Empire CMS realizes automatic transfer of word pictures

This method is a servlet, which can be used by configuring servlet-class and servlet-mapping in web.xml.

Backend (server) java service code: (uploaded to the ROOT/lqxcPics folder)

<%@ 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("Upload file exception:"+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()+"");

%>

 

Configure web.xml

 <?xml version="1.0" encoding="UTF-8"?>

<web-app version="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>

 

Front-end (page) test code:

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

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

<head>

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

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

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

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

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

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

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

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

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

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

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

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

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

</head>

<body>

     <textarea name="key of background value" id="myEditor">write your initial content here</textarea>

     <script type="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();//Load control

 

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

        

         ue.ready(function() {

             //Set the content of the editor

             ue.setContent('hello');

             //Get html content, return: <p>hello</p>

             var html = ue.getContent();

             //Get the plain text content, return: hello

             var txt = ue.getContentTxt();

             pasterMgr.SetEditor(ue);

         });

                  

     </script>

</body>

</html>

The effect after realization can upload all pictures in word in batches, which greatly improves the efficiency of picture uploading. And can keep the Word style.

 

After the pictures are uploaded, the picture addresses in the editor are all changed to the picture addresses of the server.

All the code has been uploaded to the Internet, friends in need can download and use it directly, http://blog.ncmem.com/wordpress/2019/08/07/javaword picture upload control/

Discussion group: 223813913

Guess you like

Origin blog.csdn.net/weixin_45525177/article/details/108538782