那么开始吧!
这是我的项目目录
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() );