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. hdu-2255.奔小康赚大钱(最大权二分匹配)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  2. git多账号配置,同时使用多个代码托管平台

    git多账号配置,同时使用多个代码托管平台:https://blog.csdn.net/pinnuli/article/details/81293071

  3. 基本数据类型间的运算(不包括boolean)

    一 基本数据类型的间的运算  (不包括boolean) 1.自动类型提升 : 小容量的变量和大容量的变量做运算结果用大容量的变量的类型来接收. byte , short , char -> in ...

  4. [BZOJ 2199] [USACO11JAN] 大陆议会The Continental Cowngress(2-SAT)

    [BZOJ 2199] [USACO11JAN] 大陆议会The Continental Cowngress(2-SAT) 题面 题面较长,略 分析 考虑把问题转化成一个依赖性问题 我们把每只奶牛投出 ...

  5. wamp 环境的配置

    安装完wamp之后,基本不用配置什么环境,只要将mysql添加到你的环境变量中去即可.

  6. Java8 HashMap详解(转)

    Java8 对 HashMap 进行了一些修改,最大的不同就是利用了红黑树,所以其由 数组+链表+红黑树 组成. 根据 Java7 HashMap 的介绍,我们知道,查找的时候,根据 hash 值我们 ...

  7. 垂直口风琴菜单3(jquery)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. C# http post请求帮助类

    using System; using System.Collections.Specialized; using System.IO; using System.Net; using System. ...

  9. python学习笔记(6)关键字与循环控制

    一.变量和类型 1.基本变量类型 (1)整数 (2)浮点数 (3)字符串 (4)布尔值 (5)空值 (6)函数 (7)模块 (8)类型 (9)自定义类型 print(type()) print(typ ...

  10. JavaScript基础2——下拉列表左右选择

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...