JSP_01
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的更多相关文章
- JSP页面中<%! %>和<% %>的区别
JSP声明语句:<%!声明语句%>,通常声明全局变量.常量.方法.类JSP Scriptlet:<%java代码%>,其中可包含局部变量.java语句JSP表达式:<%= ...
- JSP页面的基本结构
一:一个JSP页面由以下基本元素组成. (1)HTML标签 (2)CSS (3)变量和方法 (4)Java代码段 (5)JSP动作和指令 (6)其他脚本元素(如Javascript) 二:JSP的基本 ...
随机推荐
- Java学习day8面向对象编程2-类的属性和方法
一.类的属性 1.语法格式 修饰符 类型 属性名 = 初值 说明:修饰符private:该属性只能由该类的方法使用.在同一类内可见.使用对象:变量.方法. 注意:不能修饰类(外部类) 修饰符pu ...
- shutdown的几种方法和利弊
1.shutdown normal 正常方式关闭数据库. 2.shutdown immediate 立即方式关闭数据库. 在SVRMGRL中执行shutdown imme ...
- BlockingQueue 阻塞队列(生产/消费者队列)
1:BlockingQueue的继承关系 java.util.concurrent 包里的 BlockingQueue是一个接口, 继承Queue接口,Queue接口继承 Collection Blo ...
- React手稿 - Context
Context Context提供了除props之外的传参数的方式. Context是全局跨组件传递数据的. API React.createContext ``` const {Provider, ...
- 问题 J: 老肖数等式
问题 J: 老肖数等式 时间限制: 1 Sec 内存限制: 128 MB提交: 1594 解决: 741[提交] [状态] [命题人:jsu_admin] 题目描述 老肖前几年当了小学数学老师,他 ...
- 关于html5 video的连续播放
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- redis 安装和运行
安装redis 在CentOs虚拟机上:yum install redis,可能会出现以下错误: 解决方式:先输入yum install epel-release,之后输入:redis-server启 ...
- 封装RF keyword
*** Settings ***Library SeleniumLibrary *** Keywords ***打开浏览器 [Arguments] ${url} ${browser} Open Bro ...
- MTCNN 人脸检测
demo.py import cv2 from detection.mtcnn import MTCNN # 检测图片中的人脸 def test_image(imgpath): mtcnn = MTC ...
- bzoj4940 [Ynoi2016]这是我自己的发明 莫队+dfs序
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4940 题解 对于换根操作,处理方法就很套路了. 首先先假定以 \(1\) 为根做一遍 dfs, ...