
无需加好友免费技术支持
Enjoy必须应用模板引擎jar与此同时给予包Enjoy模板引擎的源码jar,存储地址:连接:
提取码:gldr 。
拷贝enjoy-4.6.jar和enjoy-4.6-sources.jar2个jar到上图的lib如下图所显示,文件目录。
在src中新创建包com.why.utils,如下图。
点击包com.why.utils,并按ctr n,输入发生的窗口ser,如下图
在上图中挑选web目录下的Servlet,并点击Next,将Java package将输入框中的信息改动为com.why,并把得到聚焦点的输入框输入Enjoy,如下图。
点击finish,会到编码区弹出来Enjoy.java文件,但会出错,如下图所显示。
点击enjoy点击鼠标点击表明下面的图。
点击上图里的Build Path里的Configure Build Path..,下列提示框发生
挑选Libraries点击右边菜单栏Add Library..,下列提示框发生。
挑选Server Runtime,并点击Next。
这时将enjoy新项目加上到tomcat并运行,输入电脑浏览器
下列结果显示取得成功。
从现在起配备Enjoy模板引擎,包com.why.utils下新创建EngineUtil类,并输入下列编码。
package com.why.utils;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.jfinal.template.Engine;
import com.jfinal.template.Template;
public class EngineUtil {
public static Engine getInstance() {
Engine engine = Engine.use();
engine.setDevMode(true);
engine.setBaseTemplatePath(null);
engine.setToClassPathSourceFactory();
return engine;
}
public static void write(String url, HttpServletResponse response) throws IOException {
Template template = EngineUtil.getInstance().getTemplate(url);
String index = template.renderToString();
response.getWriter().write(index);
}
}
在Enjoy.java文件中的doGet在办法中输入下列编码
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
EngineUtil.write("/index.html", response);
}点击enjoy新项目,并按ctr n,输入发生的输入框sour,结论如下所示
挑选Source Folder,并按Next,输入弹出窗口view,如下图
点击Finish,点击新创建的view文件夹并按ctr n,输入弹出侧输入框html,如下图。
点击Next,在File name输入框index.html,并按Finish。
假如你的index.html在Webcontent在目录下,它能够手动式拖拽到view目录下。在index.html中的body输入下列编码并储存。
#("abcd".substring(0, 2))运行tomcat并浏览电脑浏览器里的网址:
下列结果显示,集成化表明集成化Enjoy模版进行。