JSP

window下Tomcat的下载安装及配置

1、安装
2、基本语法
3、项目导出及部署
4、JSP注释

1、安装

绿色软件,下载解压即安装成功。

安装目录:

  • bin:存放启动和关闭tomcat的脚本
  • conf:存放tomcat服务器的各种配置文件
  • lib:存放tomcat的依赖jar包
  • logs:存放tomcat执行时生成的日志文件
  • temp:存放一些临时文件
  • webapps:存放web应用
  • work:存放一些中间文件
  • LICENSE
  • NOTTICE
  • tomcat.ico
  • Uninstall.exe

    配置环境变量

    安装目录

2、基本语法

  1. 用 JSP 向浏览器输出 hello world
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    JSP表达式输出:<%="hello world" %>
    <br/>
    <%
    String str = "hello world";
    out.print(str);
    %>
    </body>
    </html>

3、项目导出及部署

  • export-warfile
  • 将war文件放进.\Tomcat8\webapps目录下。
  • 启动tomcat后war文件自动解压
  • 浏览器浏览localhost:8080/JSPStyudy/01/hello.jsp

4、JSP注释

HTML注释:

1
2
<!-- this is body-->
<!-- today is <%=new java.util.Date().toString() %> -->

JSP注释:

1
2
3
<%--
this is JSP comments.
--%>

JSP程序段中的注释:

1
2
3
4
<%--
//String str = "hello world"; 单行注释
/*多行注释*/
--%>

谢谢你请我吃糖果!