1.原始jsp模板
查看初始jsp创建模板:File---Setting---Editor---File and Code Templates---Other---Jsp files---JspFile.jsp,可在⑤处重新定义jsp模板,编写完成后,Apply,OK,下次在新建jsp文件时,即可建立所定义模板的jsp页面。
初始jsp模板代码如下:
<%--
Created by IntelliJ IDEA.
User: ${USER}
Date: ${DATE}
Time: ${TIME}
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>#[[$Title$]]#</title>
</head>
<body>
#[[$END$]]#
</body>
</html>
自定义jsp模板代码:
<%@page pageEncoding="UTF-8" contentType="text/html; UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>请在此输入标题</title>
</head>
<body>
</body>
</html>
完整版的jsp模板代码:
<%--
Created by IntelliJ IDEA.
User: ${USER}
Date: ${DATE}
Time: ${TIME}
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath %>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
</head>
<body>
</body>
</html>
2.重新定义jsp页面模板
File---Setting---Editor---Live Templates---选择JSP---新建Live Template,指定后缀名jsp,编写模板代码,配置变量,定义作用范围,Apply,OK即可
完整版的jsp模板代码:见上方
3.快速创建jsp页面
File---Setting---Editor---File and Code Templates---Files---+---命名jsp---指定后缀jsp,编写jsp页面模板代码,Enable Live Templates,Apply,OK
模板代码见上方
4.新建jsp页面
或
参考链接: