jsp解決kindeditor線上編輯器struts圖片上傳問題

來源:互聯網
上載者:User

標籤:

1、下載

    官網下載ckeditor,解壓後去掉不需要的部分,僅需保留plugin,lang,theme檔案夾,這三個檔案夾中用不到的東西可以刪除, 比如lang檔案下存放所有語言檔案js,僅僅  保留en.js和zh_CN.js即可,保留jsp檔案夾下的json_upload.jsp檔案和 kindeditor.js檔案即可,把jsp下面的jar匯入

  

線上編輯器:http://kindeditor.net/
 

 

2、修改json_upload.jsp

  修改json_upload.jsp檔案儲存路徑即可修改一下兩句即可。

  //檔案儲存目錄路徑
  String savePath = pageContext.getServletContext().getRealPath("/upload");

  //檔案儲存目錄URL,此處為絕對路徑
  String saveUrl  = request.getContextPath()+"/upload";

 3、可選

  obj.put("url", request.getContextPath()+"/img/" + newFileName);//修改返回到編輯器顯示的圖片

4、在plugins/images/image.js修改

          uploadJson = K.undef(self.uploadJson, self.basePath + ‘jsp/upload_json.jsp‘)

5、在plugins/filemanager/filemanager.js修改

        fileManagerJson = K.undef(self.fileManagerJson, self.basePath + ‘jsp/file_manager_json.jsp‘),

6、jsp中

  <link rel="stylesheet" href="<%=application.getContextPath() %>/themes/default/default.css" />
    <script charset="utf-8" src="<%=application.getContextPath() %>/js/kindeditor.js"></script>
    <script charset="utf-8" src="<%=application.getContextPath() %>/lang/zh_CN.js"></script>

  <script charset="utf-8" src="<%=application.getContextPath() %>/lang/zh_CN.js"></script>
              <script>
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create(‘textarea[id="content"]‘, {
                    filterMode:false,
                    resizeType : 1,
                    allowPreviewEmoticons : true,
                    allowImageUpload : true,
                    items : [
                        ‘fontname‘, ‘fontsize‘, ‘|‘, ‘forecolor‘, ‘hilitecolor‘, ‘bold‘, ‘italic‘, ‘underline‘,
                        ‘removeformat‘, ‘|‘, ‘justifyleft‘, ‘justifycenter‘, ‘justifyright‘, ‘insertorderedlist‘,
                        ‘insertunorderedlist‘, ‘|‘, ‘emoticons‘, ‘image‘, ‘link‘]
                    
                    });
                K(‘input[name=submit]‘).click(function(e) {
                    editor.value=editor.text();
                });
            });
        </script>

       <textarea  tabindex="4"  name="brand.content" id="content" style="width:80.2%"></textarea>

----------------------------struts----------------------------------------------------

1、struts直接<url-pattern>/*</url-pattern>會攔截了線上編輯器的url,所以需要進行下面的配置,這個只是解決那個問題的其中一種

2、自訂filter

public class KindeditorUrlFilter extends StrutsPrepareAndExecuteFilter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
        
        HttpServletRequest request = (HttpServletRequest) req;    
           //不過濾的url    
           String url = request.getServletPath();  
           
           if ("/js/jsp/file_manager_json.jsp".equals(url)) {     
                
               chain.doFilter(req, res);    
           }else if("/js/jsp/upload_json.jsp".equals(url)){  
               chain.doFilter(req, res);  
           }else{    
               //System.out.println("使用預設的過濾器");    
               super.doFilter(req, res, chain);    
           }    
    }
}

3、web.xml配置filter

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>com.dan.action.KindeditorUrlFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

jsp解決kindeditor線上編輯器struts圖片上傳問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.