javaWeb_jsp_10<ckeditor&SmartUpload>

一.ckeditor

ckeditor是一个富文本

1首先我们要引入cheditor的类库:

然后在使用注意:

Ckedtiord.replace 存放的值要与文本域的name值一致

 

这样就可以获得一个富文本框的效果

 

---------------------------------------------------------------------------------------------------------------------------------

二.SmartUpload

SmartUpload组件特点
     使用简单:编写少量代码,完成上传下载功能

        能够控制上传内容

        能够控制上传文件的大小、类型

        缺点:目前已停止更新服务

1.使用第三方上传插件:smartUpload

2.明确:

  a.数据库表中的列中存的是文件路径;

图片也要传到服务器上(将本地文件传到服务器项目中,然后将路径存入表字段中)

3.步骤:

  第一:在项目中导入jspsmartupload.jar文件包

  第二:在<form>表单中添加表单属性:enctype="multipart/form-data"

  第三:了解file类与smartupload类中的方法

文件会有一些上传限制

限制文件的上传类型

允许上传类型:

samrt.setAllowedFilesList("gif,jpg,doc,rar");

不允许上传类型:

samrt.setDeniedFilesList("jsp,asp,php,aspx");

上传大小上限

(2*1024*1024)

编码方式

<%@page import="com.jspsmart.upload.Request"%>

<%@page import="com.jspsmart.upload.File"%>

<%@page import="com.jspsmart.upload.SmartUpload"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%

//一、单文件上传

//实例化

SmartUpload su=new SmartUpload();

//初始化  pageContext是jsp的九大内置对象之一  作用域仅限于当前的jsp页面

su.initialize(pageContext);

//设置相关要求

su.setCharset("utf-8");//设置编码方式

su.setAllowedFilesList("jpg,png,jpeg,gif");//设置允许上传的文件类型 用逗号隔开

su.setDeniedFilesList("exe,jsp,js,bat");//设置禁止上传的文件类型

su.setMaxFileSize(1024*1024*2);//设置文件的最大大小 不超过2M  

//上传到服务器内存

su.upload();

//--自动找web项目的根目录

/*  String path="images/";

//获取文件

File file=su.getFiles().getFile(0);

//做判断

if(file.isMissing()==false){//上传了文件

//设置文件的编码方式

file.setCharset("utf-8");

path+=file.getFileName();//拼接上原有的文件名  

file.saveAs(path, SmartUpload.SAVE_VIRTUAL);//自动找web项目的根目录

}

out.print(path);  */

//--手动找web项目的根目录

/*  String path="images/";

//E:\JavaWeb\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\q6\

String webPath=this.getServletContext().getRealPath("/");

//获取文件

 File file=su.getFiles().getFile(0);

//做判断

if(!file.isMissing()){//上传了文件

//设置文件的编码方式

file.setCharset("utf-8");

path+=file.getFileName();//拼接上原有的文件名

file.saveAs(webPath+path);//手动找web项目的根目录

}

out.print(path);  */

//拿表单的其他值 建议放在文件上传之后

/* Request req=su.getRequest();

String name=req.getParameter("iname");

out.print("用户名:"+name); */

//二、多文件上传

//拿到所有的文件

/* Files fs=su.getFiles();

//拿到总数目 循环

for(int i=0;i<fs.getCount();i++){

//依次拿到每一个文件 依次进行上传

File file=fs.getFile(i);

//String path="images/";

//做判断

if(!file.isMissing()){//上传了文件

//设置文件的编码方式

file.setCharset("utf-8");

path+=file.getFileName();

file.saveAs(path, SmartUpload.SAVE_VIRTUAL);//自动找web项目的根目录

}

out.print(path+"<br/>");

}

 */

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值