freemarker.template.TemplateNotFoundException:

北九道 2018-07-05 05:12:43
1、背景:
JFinal Freemarker CKEditor: web项目
2、业务:
做个CKEditor的编辑器,在向编辑器里面插入图片时候,url跑到后台处理,保存图片到服务器。然后在前台渲染上传的照片。

3、后台console exception:
2018-07-05 17:00:37,181 [com.jfinal.core.ActionHandler.handle(ActionHandler.java:102)]-[ERROR] /image/uploadImage?CKEditor=content&CKEditorFuncNum=1&langCode=zh-cn
com.jfinal.render.RenderException: freemarker.template.TemplateNotFoundException: Template not found for name "/image/uploadImage.html".
The name was interpreted by this TemplateLoader: WebappTemplateLoader(subdirPath="/", servletContext={contextPath="", displayName=null}).
at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:147)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:97)
at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:47)
at com.jfinal.ext.handler.AddHeaderHandler.handle(AddHeaderHandler.java:50)
at com.jfinal.ext.handler.CacheControlHeaderHandler.handle(CacheControlHeaderHandler.java:48)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1139)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "/image/uploadImage.html".
The name was interpreted by this TemplateLoader: WebappTemplateLoader(subdirPath="/", servletContext={contextPath="", displayName=null}).
at freemarker.template.Configuration.getTemplate(Configuration.java:1833)
at freemarker.template.Configuration.getTemplate(Configuration.java:1646)
at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:143)
... 22 more

4、CKEditor的配置:
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here.
// For complete reference see:
// http://docs.ckeditor.com/#!/api/CKEDITOR.config

// The toolbar groups arrangement, optimized for two toolbar rows.
config.toolbarGroups = [
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
{ name: 'links' },
{ name: 'insert' },
{ name: 'forms' },
{ name: 'tools' },
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'others' },
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
{ name: 'styles' },
{ name: 'colors' },
{ name: 'about' }
];

// Remove some buttons provided by the standard plugins, which are
// not needed in the Standard(s) toolbar.
config.removeButtons = 'Underline,Subscript,Superscript';

// Set the most common block elements.
config.format_tags = 'p;h1;h2;h3;pre';

// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';
config.image_previewText=' ';
config.filebrowserUploadUrl="/image/uploadImage";
};

5、后台处理类:
public void uploadImage(){//CKEditorl的图片上传接口;
UploadFile file = getFile();
String fileName = UuidUtil.getUuidByJdk(true);
String suffix = file.getFileName().substring(file.getFileName().indexOf("."));
try {
String contentPath = getRequest().getSession().getServletContext().getRealPath("/");
String dirPath = contentPath + "/upload/image/";

File dirFile = new File(dirPath);
if(!dirFile.exists()) {
dirFile.mkdirs();
}
FileUtil.copyFile(contentPath+"/upload/"+file.getFileName(), dirPath+fileName+suffix);
File preFile = new File(contentPath+"/upload/"+file.getFileName());
if(preFile.exists()){
preFile.delete();
}
//renderRtn(RtnFactory.newSucc("/upload/image/" + fileName+suffix));

String callback =getPara("CKEditorFuncNum");
HttpServletResponse response = getResponse();
String fullContentType ="text/html;charset=UTF-8";
response.setContentType(fullContentType); //定义contentType格式,否则可能字符会被转义,上传后的图片地址无法自动写入
PrintWriter writer = response.getWriter();
writer.write("<script type=\"text/JavaScript\">"
+"window.parent.CKEDITOR.tools.callFunction("+ callback + ",'" + "/upload/image/" + fileName+suffix+ "','')"
+"</script>");
writer.flush();

} catch (IOException e) {
e.printStackTrace();
renderRtn(RtnFactory.exception);
}
...全文
2037 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧