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的基本 ...
随机推荐
- Eclipse解除已关联的Coding远程仓库,重新关联github上的远程仓库
1.在Eclipse中的Git Repositories中找到要解除的仓库,依次找到Remote--origin[视自己的实际情况选择], 2.选中origin,右键选择Delete Remote , ...
- dfs(找环)
https://codeforces.com/problemset/problem/1249/B2 B2. Books Exchange (hard version) time limit per t ...
- (一:NIO系列)JAVA NIO 简介
出处:JAVA NIO 简介 Java 中 New I/O类库 是由 Java 1.4 引进的异步 IO.由于之前老的I/O类库是阻塞I/O,New I/O类库的目标就是要让Java支持非阻塞I/O, ...
- django 开发中数据库做过什么优化??
1.设计表时,尽量少使用外键,因为外键约束会影响插入和删除性能: 2.使用缓存,减少对数据库的访问: 3.在 orm 框架下设置表时,能用 varchar 确定字段长度时,就别用 text: 4.可以 ...
- python 模块调用的几种方式
在python里面又很多模块,或者引用第三方模块,python 模块调用的几种方式,下面详细解说 1,import 模块名 2,from 模块 import 模块里面的小功能 3,from 模块 ...
- Python2/3 安装各类包的教程
1.pycryptodome(pyCrypto) pyCrypto包已经失效了,需要替换为pycryptodome 有SSR直接 pip install pycryptodome 国内用 pip in ...
- c#中decimal的去0显示
在近来的开发中,遇到到了decimal中显示0的问题,搞了很久才搞好了,现在就简单介绍一下其中一小部分,其他的网上很上很多 public static string DecimalToString(d ...
- 详解Document.Cookie
转自:https://www.jb51.net/article/77009.htm 具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. 同时 ...
- python 安装 pip ,并使用pip 安装 filetype
闲话少说,直接上操作. python版本为2.7.6 可以直接到官网下载,我也提供一个百度云的下载地址 https://pan.baidu.com/s/1kWPXG8Z 这个是window版本,lin ...
- CentOS7安装mysql8.0编译报错集合
以下都是我安装mysql8.0遇到的一些报错和解决方法 1.does not appear to contain CMakeLists.txt. 原因:mysql下载的源码包不对 解决方法:下载正确的 ...