0
点赞
收藏
分享

微信扫一扫

IDEA中快速创建jsp页面模板

color_小浣熊 2022-04-27 阅读 83
idea

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模板代码:

  <%--
    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模板代码:

  
  <%--
    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>
  ​

3.快速创建jsp页面

       File---Setting---Editor---File and Code Templates---Files---+---命名jsp---指定后缀jsp,编写jsp页面模板代码,Enable Live Templates,Apply,OK

4.新建jsp页面

或 

 

参考链接:

  • IDEA初始jsp模板和修改jsp模板_jsonCC的博客-CSDN博客_ideajsp模板

  • idea配置JSP模板 - 简书

  • idea的jsp模板 - Arborblog - 博客园

举报

相关推荐

0 条评论