`

百度ueditor使用心得

 
阅读更多
包自己下载,此处有提供;
ueditor难度在于图片和附件的上传配置。
1、
<script type="text/javascript" src="ueditor/ueditor.config.js" ></script> 
<script type="text/javascript" src="ueditor/ueditor.all.js" ></script>

2、编辑框的实例化,js代码:
var describe = UE.getEditor('myEditor');

html代码:
<div id="myEditor" style="height:100px;"></div>

3、需注意到的是为编辑框赋值:
var examContentAnalysis = UE.getEditor('myEditor8');   
	examContentAnalysis.ready(function(){
		examContentAnalysis.setContent('${tmEduExamContent.examContentAnalysis}');
	});


4、图片上传配置:
导入ueditor.config.js,再项目中导入commons-fileupload-1.2.1.jar和ueditor.jar包
首先配置URL为你的ueditor针对项目下的相对目录
var URL;
	URL = window.UEDITOR_HOME_URL = "/TMRemoteEdu/ueditor/";
    URL = window.UEDITOR_HOME_URL || (function(){

其次配置图片保存目录
 //图片上传配置区
        ,imageUrl:URL+"jsp/imageUp.jsp"             //图片上传提交地址
        ,imagePath:URL + "/upload/"                     //图片修正地址,引用了fixedImagePath,如有特殊需求,可自行配置
        //,imageFieldName:"upfile"                   //图片数据的key,若此处修改,需要在后台对应文件修改对应参数
        //,compressSide:0                            //等比压缩的基准,确定maxImageSideLength参数的参照对象。0为按照最长边,1为按照宽度,2为按照高度
        //,maxImageSideLength:900                    //上传图片最大允许的边长,超过会自动等比缩放,不缩放就设置一个比较大的值,更多设置在image.html中

        //附件上传配置区
        ,fileUrl:URL+"jsp/fileUp.jsp"               //附件上传提交地址
        ,filePath:URL + "/upload/"                   //附件修正地址,同imagePath
        //,fileFieldName:"upfile"                    //附件提交的表单名,若此处修改,需要在后台对应文件修改对应参数
 //图片在线管理配置区
        ,imageManagerUrl:URL + "jsp/imageManager.jsp"       //图片在线管理的处理地址
        ,imageManagerPath:URL + "/upload/" 

然后就是jsp页面的处理
imageUp.jsp如下:
 up.setSavePath("../upload");

fileUp.jsp如下:
up.setSavePath("../upload"); //保存路径

5、图片本地管理要修改:
imageManager.jsp
public String getRealPath(HttpServletRequest request,String path){
	ServletContext application = request.getSession().getServletContext();
	String str = application.getRealPath(request.getServletPath());
	return new File(new File(str).getParent()).getParent() + path;
}

然后如下:
String path = "\\upload";
	String imgStr ="";
	String realpath = getRealPath(request,path)+"/";
	List<File> files = getFiles(realpath,new ArrayList());
	for(File file :files ){
		imgStr+=file.getPath().replace(getRealPath(request,path),"")+"ue_separate_ue";
	}
	if(imgStr!=""){
        imgStr = imgStr.substring(0,imgStr.lastIndexOf("ue_separate_ue")).replace(File.separator, "/").trim();
    }
	out.print(imgStr);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics