JSP 頁面引入 UEditor 後,編輯器僅渲染為一個簡陋的 `
UEditor 核心配置文件 **`jsp/config.json` (或 `php/config.json` 等后端語言對應目錄)** **不支持註釋**。
默認配置文件中包含大量**中文註釋** (如 `/* 這裡配置... */`),導致前端 `UE.getEditor` 初始化時 `JSON.parse` 失敗,配置對象為空,編輯器退化為基礎文本域。
{
"imageActionName": "uploadimage",
"imageFieldName": "upfile",
"imageMaxSize": 2048000,
"imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
"imageCompressEnable": true,
"imageCompressBorder": 1600,
"imageInsertAlign": "none",
"imageUrlPrefix": "",
"imagePathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"scrawlActionName": "uploadscrawl",
"scrawlFieldName": "upfile",
"scrawlPathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"scrawlMaxSize": 2048000,
"scrawlAllowFiles": [".bmp", ".png", ".jpg", ".jpeg", ".gif"],
"catcherActionName": "catchimage",
"catcherFieldName": "source",
"catcherPathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
"videoActionName": "uploadvideo",
"videoFieldName": "upfile",
"videoPathFormat": "/ueditor/jsp/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}",
"videoMaxSize": 102400000,
"videoAllowFiles": [".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"],
"fileActionName": "uploadfile",
"fileFieldName": "upfile",
"filePathFormat": "/ueditor/jsp/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}",
"fileMaxSize": 51200000,
"fileAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"],
"imageManagerActionName": "listimage",
"imageManagerListPath": "/ueditor/jsp/upload/image/",
"imageManagerListSize": 20,
"imageManagerUrlPrefix": "",
"imageManagerInsertAlign": "none",
"imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
"fileManagerActionName": "listfile",
"fileManagerListPath": "/ueditor/jsp/upload/file/",
"fileManagerListSize": 20,
"fileManagerUrlPrefix": "",
"fileManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"]
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<script type="text/javascript" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<script id="editor" type="text/plain" style="width:100%;height:400px;"></script>
<script type="text/javascript">
var ue = UE.getEditor('editor', {
UEDITOR_HOME_URL: 'ueditor/', // 關鍵:指定 UEditor 根目錄
serverUrl: 'ueditor/jsp/controller.jsp' // 后端統一處理接口
});
</script>
</body>
</html>
| 檢查項 | 正確狀態 |
|---|---|
| config.json 編碼 | UTF-8 無 BOM |
| config.json 格式 | 純 JSON,無任何註釋、無尾隨逗號 |
| UEDITOR_HOME_URL | 指向 ueditor/ 目錄 (以 / 結尾) |
| serverUrl | 指向后端控制器 (如 controller.jsp) |
| 上傳目錄權限 | Tomcat 進程對 upload 目錄有讀寫權限 |
| 瀏覽器控制台 | 無 404 (JS/CSS/配置)、無 JS 錯誤 |
UEditor JSP 版「只有輸入框無工具欄」99% 是 **`config.json` 含中文註釋導致 JSON 解析失敗**。**刪除配置文件所有註釋,確保純 JSON 格式** 即可完美解決。配合正確設置 `UEDITOR_HOME_URL` 和 `serverUrl`,編輯器將完整加載工具欄、上傳、對話框等全部功能。