1.定义局部变量、输出语句
 <!doctype html>
<html>
<head>
<title>定义局部变量、输出语句</title>
</head>
<body>
<%
int i = 1;//定义局部变量
String info = "www.baidu.com";
out.println("<h1>"+i+"</h1>"); //编写语句
out.println("<h1>"+info+"</h1>");
%>
</body>
</html>

2.定义全局变量、方法、类

 <!doctype html>
<html>
<head>
<title>定义全局变量、方法、类</title> </head>
<body>
<%!
public static final String info="www.baidu.com";
%> <%!
public int add(int i,int j){
return i+j;
}
%> <%!
class User{
private String name;
private int age;
public User(String name,int age){
this.name=name;
this.age=age;
}
public String toString(){
return "name="+name+",aga="+age;
}
} %> <%
out.println("<h1>"+info+"</h1>");
out.println("<h1>1+3="+add(1,3)+"</h1>");
out.println("<h1>"+new User("liuyang",23)+"</h1>");
%> </body>
</html>

3.输出语句

 <!doctype html>
<html>
<head>
<title>定义全局变量、方法、类</title>
</head>
<body>
<%
String info = "www.baidu.com";
int i = 1;
%>
<h1> i = <%=i%> </h1>
<h1>info =<%=info%></h1>
<h1>name=<%="liuyang"%></h1>
</body>
</html>

4.注释方法:

  <!-- 显示注释 -->
  <%-- 隐式注释:JSP 注释 --%>
  // 隐式注释:单行注释
  /* 隐式注释:多行注释 */

5.JSP 创建表格1 out.println输出

 <!doctype html>
<html>
<head>
<title>Table_out_print</title> </head>
<body>
<%
int rows = 10;
int cols = 10;
int count = 1;
out.println("<table border='1' width='70%'>");
for(int i=1;i<=rows;i++){
out.println("<tr>");
for(int j=1;j<=cols;j++){
out.println("<td>"+(count));
count++;
}
out.println("</tr>");
} out.println("</table>"); %> </body>
</html>

6.JSP 创建表格2  <%= %>输出

 <!doctype html>
<html>
<head>
<title>Table_out_jsp</title>
</head>
<body>
<table border='1' width='70%'>;
<%
int rows = 10;
int cols = 10;
int count = 1;
for(int i=1;i<=rows;i++){
%>
<tr>
<%
for(int j=1;j<=cols;j++){
%> <td> <%=(count)%>
</td> <%
count++;
}
%> </tr>
<%
}
%>
</table> </body>
</html>

JSP的指令元素

  1、page指令:配置整个页面属性,一共13个属性

JSP_01的更多相关文章

  1. JSP页面中<%! %>和<% %>的区别

    JSP声明语句:<%!声明语句%>,通常声明全局变量.常量.方法.类JSP Scriptlet:<%java代码%>,其中可包含局部变量.java语句JSP表达式:<%= ...

  2. JSP页面的基本结构

    一:一个JSP页面由以下基本元素组成. (1)HTML标签 (2)CSS (3)变量和方法 (4)Java代码段 (5)JSP动作和指令 (6)其他脚本元素(如Javascript) 二:JSP的基本 ...

随机推荐

  1. package.json说明

    package.json是什么? 直接的说:就是管理你本地安装的npm包 一个package.json文件可以做如下事情: 展示项目所依赖的npm包 允许你指定一个包的版本[范围] 让你建立起稳定,意 ...

  2. 扩展欧几里得算法详解(exgcd)

    一.前言 本博客适合已经学会欧几里得算法的人食用~~~ 二.扩展欧几里得算法 为了更好的理解扩展欧几里得算法,首先你要知道一个叫做贝祖定理的玄学定理: 即如果a.b是整数,那么一定存在整数x.y使得$ ...

  3. 2019 Multi-University Training Contest 2 - 1009 - 回文自动机

    http://acm.hdu.edu.cn/showproblem.php?pid=6599 有好几种实现方式,首先都是用回文自动机统计好回文串的个数. 记得把每个节点的cnt加到他的fail上,因为 ...

  4. 【JAVA】格式化打印printf的使用

    格式化打印printf的使用 import java.util.Date; /** * 使用printf输出 */ /**关键技术点 * 使用java.io.PrintStream的printf方法实 ...

  5. vue.js(12)--过滤器

    vue中的全局过滤器与定义私有过滤器 全局过滤器 <!DOCTYPE html> <html lang="en"> <head> <met ...

  6. VMWare15 安装 Mac OS 系统

    文章目录VMWare15 安装 Mac OS 系统安装环境工具准备准备工作MAC虚拟机设置启动MAC前准备工作安装系统安装VMware Tool注意事项参考链接安装环境WIN10VMware Work ...

  7. <s:iterator>标签迭代数据不显示

    <s:iterator>标签迭代数据不显示 <s:iterator value="#request.voteOptionList" var="voteO ...

  8. GitHub 搭建博客,出现 hexo g -d 报错

    想搭建一个个人博客,但是在将博客推送到Github上的时候在git bash 下运行hexo g -d命令出现错误: 错误如下:  fatal: HttpRequestException encoun ...

  9. JS window对象 返回前一个浏览的页面 back()方法

    JS window对象 返回前一个浏览的页面 back()方法,加载 history 列表中的前一个 URL. 语法: window.history.back();   返回前一个浏览的页面 back ...

  10. 搭建Keepalived+LNMP架构web动态博客 实现高可用与负载均衡

    环境准备: 192.168.193.80  node1 192.168.193.81 node2 关闭防火墙 [root@node1 ~]# systemctl stop firewalld #两台都 ...