JavaWEB10CKeditor&SmartUpload

本文介绍了Java Web开发中常用的富文本编辑器CKeditor,以及如何使用SmartUpload插件进行文件上传。CKeditor的使用步骤包括从官网下载、解压并引入到项目中。对于文件上传,讨论了图片应保存到服务器硬盘而非数据库,并详细阐述了SmartUpload的环境配置和使用方法,包括设置表单enctype属性以及利用File类进行文件操作。
摘要由CSDN通过智能技术生成

一.富文本编辑器


   1. 概述


        富文本编辑器,Rich Text Editor, 简称 RTE, 是一种可内嵌于浏览器,所见即所得的文本编辑器,类似于 Microsoft Word 的编辑功能。


   2 常用的富文本编辑器


        ①ckeditor


        ②Kindeditor
        ③ueditor
        ④wangEditor
        ⑤SmartMarkUP
        ⑥Control.Editor
        ⑦EditArea
        ⑧Free Rich Text Editor


  3. CKeditor的使用步骤


        【步骤一】官网https://ckeditor.com/ 下载-解压-引入
        【步骤二】
  

 <script type="text/javascript" src = "../ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        CKEDITOR.replace("ncontent");
    </script>

二、SmartUpload插件

   1. [问题]图片上传是到数据库还是到服务器?


    文件路径保存到数据库中,而把文件上传到服务器【tomcat】的硬盘中。

2[使用步骤]


①环境准备:使用SmartUpload组价需要在项目中引入jspsmartupload.jar文件
    --将jspsmartupload.jar添加到web-inf\lib目录下

②需要设置表单的enctype属性--设置enctype属性后表单必须以post方式提交。
    --<form enctype = "multipart/form-data" method = "post">

③jsp smartupload.jar包中的File类
    --封装了单个上传文件所包含的所有信息
    saveAS() | isMissing() | getFieldName() | getFileName()

      
----------------------------------------------------------------------------------------------------------------
案例:文件上传


 

<form action = "doAddFile.jsp" enctype="multipart/form-data" method = "post">
        <input type = "file" name = "file"/>
        <input type = "submit" value = "上传"/>    
</form>

<%
    //声明并实例化SmartUpload对象
    SmartUpload su = new SmartUpload();
    su.initialize(pageContext);//初始化SmartUpload对象
    
    //定义文件上传类型
    String allowed = "gif,jpg,doc,rar";
    //定义不许上传类型
    String denied = "jsp,asp,php,aspx,html,htm,exe,bat";
    //设置上传文件大小
    int file_size = 10*1024*1024;
    File file = null;
    try{
        //定义允许上传文件类型   
        su.setAllowedFilesList(allowed);
        //不允许上传文件类型   
        su.setDeniedFilesList(denied);        
        //单个文件最大限制   
        su.setMaxFileSize(file_size);                        
        su.setCharset("utf-8");
        //开始文件上传
        su.upload();//服务器的内存中
        
        //得到第一个上传的文件
        //System.out.println(su.getFiles().getSize());
        file = su.getFiles().getFile(0);
        String path = null;
        if(!file.isMissing()){//如果上传了文件
            path = "upload\\";//文件保存的路径
            path+=file.getFileName();//加上了文件名
            file.saveAs(path, SmartUpload.SAVE_VIRTUAL);
        }
        System.out.println(path);
        
    }catch(Exception e){
        e.printStackTrace();
    }


%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值