ckeditor
使用三部曲
1.下载
2.引入
3.使用
<!-- 引入ckeditor的类库 -->
<script src="../ckeditor/ckeditor.js"></script><p>
<label> 内容 </label>
<textarea name="ncontent" id="nr" cols="70" rows="10"></textarea>
<script>
CKEDITOR.replace('ncontent');
</script>
</p>
smartupload
表单必须用enctype属性进行封装:
<form action="" method="post" enctype="multipart/form-data">
//表示表单将按照二进制的方式提交在使用smartUpload时必须严格按照如上程序进行:
SmartUpload smart=new SmartUpload(); //实例化SmartUpload上传组件
smart.initialize(pageContext); //初始化上传操作
smart.upload(); //上传准备
smart.save("upload"); //将上传文件保存在upload文件夹中当一个表单使用了enctype封装后,其他的非文件类的表单控件的内容就无法通过request内置对象取得,此时必须通过SmartUpload类中提供的getRequest()方法取得全部的请求参数。
String uname=smart.getRequest().getParameter("uname");
注意:该句代码一定要在执行完upload()方法之后才可以使用
案例
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="doindex.jsp" enctype="multipart/form-data" method="post">
头像:<input type="file" multiple="multiple" name="ifile"><br>
用户名:<input type="text" name="iname" ><br>
<input type="submit" value="注册">
<input type="reset" value="清空">
</form>
</body>
</html>
<%@page import="com.jspsmart.upload.Files"%>
<%@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"%>
<%
//问题:请问客户端的文件到底要上传到哪里
//A:放到数据库里 × 把其在服务器硬盘文件夹的路劲保存到数据库里
//B:放到服务器硬盘的某个指定文件夹 √
//一、单文件上传
//实例化
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*10);//设置文件的最大大小 不超过10M
//上传到服务器内存
su.upload();
/* //--自动找web项目的跟目录
String path="images/";
//获取文件
File file=su.getFiles().getFile(0);
if(!file.isMissing()){//上传了文件
//设置文件的编码方式
file.setCharset("utf-8");
path+=file.getFileName();//拼接上原有的文件名
file.saveAs(path,SmartUpload.SAVE_VIRTUAL);
}
out.print(path); */
/* //--手动找web项目的跟目录
String path="images/";
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); */
//不管哪种方式 只需要把path对应列
/* //拿表单的其他值 建议放在文件上传之后
Request req=su.getRequest();
String name=req.getParameter("iname");
out.print(name); */
//二、多文件上传
//拿到所有的文件
Files fs=su.getFiles();
//拿到总数目
//out.print(fs.getCount());
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);
}
out.print(path+"<br>");
}
%>