ueditor 图片上传 java_UEditor之基于Java图片上传前后端源码研究

那么开始吧!

这是我的项目目录5119a0868237e33465c9fbe6675fd956.png

1.从访问路径http://localhost:8081/Test/_examples/simpleDemo.html,我们主要是要看看,富文本框被加载出来之前,会调用哪些代码,

不卖关子,很明显,会调用后端的controller.jsp代码,因为我们已经在ueditor.config配置了:, serverUrl: URL + "jsp/controller.js

看看controller.jsp代码,上一篇文章我们已经讲了,要把这些代码看作是后端代码,很重要很重要的:

pageEncoding="UTF-8"%>

request.setCharacterEncoding( "utf-8" );

response.setHeader("Content-Type" , "text/html");

/** 项目根路径 **/

String rootPath = application.getRealPath( "/" );

/** 调用后端的ActionEnter类,并执行exec方法 **/

out.write( new ActionEnter( request, rootPath ).exec() );

%>

我们就到ActionEnter.java看看吧,这个类就是前端调用后端的唯一入口,也只有这个入口了,记住第一章有讲了,要把源码复制到src下,进行调试哦!不知道先看第一章吧!!!!!package com.baidu.ueditor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.baidu.ueditor.define.ActionMap;

import com.baidu.ueditor.define.AppInfo;

import com.baidu.ueditor.define.BaseState;

import com.baidu.ueditor.define.State;

import com.baidu.ueditor.hunter.FileManager;

import com.baidu.ueditor.hunter.ImageHunter;

import com.baidu.ueditor.upload.Uploader;

public class ActionEnter {

private HttpServletRequest request = null;

private String rootPath = null;

private String contextPath = null;

private String actionType = null;

private ConfigManager configManager = null;

/** action统一入口 **/

public ActionEnter ( HttpServletRequest request, String rootPath ) {

this.request = request;

/** rootPath = /Test/ **/

this.rootPath = rootPath;

/** actionType = config **/

this.actionType = request.getParameter( "action" );

/** contextPath = /Test **/

this.contextPath = request.getContextPath();

/** 调用ConfigManager **/

this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath, request.getRequestURI() );

}

2.ConfigManager类主要用来读取后端的配置文件,就是config.json这个文件,事实上这个文件应该放在后端的。* 配置管理器 * @author hancong03@baidu.com

*

*/

public final class ConfigManager {

private final String rootPath;

private final String originalPath;

private final String contextPath;

/** 存放备注文件 **/

private static final String configFileName = "config.json";

private String parentPath = null;

private JSONObject jsonConfig = null;

// 涂鸦上传filename定义

private final static String SCRAWL_FILE_NAME = "scrawl";

// 远程图片抓取filename定义

private final static String REMOTE_FILE_NAME = "remote";

/*

* 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件

*/

private ConfigManager ( String rootPath, String contextPath, String uri ) throws FileNotFoundException, IOException {

rootPath = rootPath.replace( "\\", "/" );

//下面的rootPath就是我的根路径

// rootPath=D:/workspace_de_client/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Test/

this.rootPath = rootPath;

this.contextPath = contextPath;

//请求路径 url = /Test/jsp/controller.jsp

if ( contextPath.length() > 0 ) {

// D:/workspace_de_client/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Test//jsp/controller.jsp

this.originalPath = this.rootPath + uri.substring( contextPath.length() );

} else {

this.originalPath = this.rootPath + uri;

}

/** 调用当前类的初始化环境方法 initEnv **/

this.initEnv();

}

//上面的方法无法就是获得controller.jsp这个类所在的真实目录而已

//下面看看initEnv()这个方法

private void initEnv () throws FileNotFoundException, IOException {

/**  **/

File file = new File( this.originalPath );

if ( !file.isAbsolute() ) {

file = new File( file.getAbsolutePath() );

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值