分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

JSP_01

发布时间:2023-09-06 01:30责任编辑:苏小强关键词:暂无标签
1.定义局部变量、输出语句
 1 <!doctype html> 2 <html> 3 ????<head> 4 ????????<title>定义局部变量、输出语句</title> ????????5 ????</head> 6 ????<body> 7 ????????<% 8 ????????????int i = 1;//定义局部变量 9 ????????????String info = "www.baidu.com"; ???????????10 ????????????out.println("<h1>"+i+"</h1>"); ?//编写语句11 ????????????out.println("<h1>"+info+"</h1>"); 12 ????????%> ????13 ????</body>14 </html>

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

 1 <!doctype html> 2 <html> 3 ????<head> 4 ????????<title>定义全局变量、方法、类</title> 5 ?????????6 ????</head> 7 ????<body> 8 ????????<%! 9 ????????????public static final String info="www.baidu.com";10 ????????%>11 ????????12 ????????<%!13 ????????????public int add(int i,int j){14 ????????????????return i+j;15 ????????????}16 ????????%>17 ????????18 ????????<%!19 ????????????class User{20 ????????????????private String name;21 ????????????????private int age;22 ????????????????public User(String name,int age){23 ????????????????????this.name=name;24 ????????????????????this.age=age; ???????????????????25 ????????????????}26 ????????????????public String toString(){27 ????????????????????????return "name="+name+",aga="+age;28 ????????????????}29 ????????????}30 ????????????31 ????????%>32 ????????33 ????????<%34 ????????????out.println("<h1>"+info+"</h1>");35 ????????????out.println("<h1>1+3="+add(1,3)+"</h1>");36 ????????????out.println("<h1>"+new User("liuyang",23)+"</h1>");37 ????????%>38 ?????39 ????</body>40 </html>

3.输出语句

 1 <!doctype html> 2 <html> 3 ????<head> 4 ????????<title>定义全局变量、方法、类</title> ????????5 ????</head> 6 ????<body> 7 ????????<% 8 ????????????String info = "www.baidu.com"; 9 ????????????int i = 1;10 ????????%> ???????11 ????????<h1> i = <%=i%> </h1> ???????12 ????????<h1>info =<%=info%></h1> ???????13 ????????<h1>name=<%="liuyang"%></h1> ???????????14 ????</body>15 </html>

4.注释方法:

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

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

 1 <!doctype html> 2 <html> 3 ????<head> 4 ????????<title>Table_out_print</title> 5 ?????????6 ????</head> 7 ????<body> 8 ????????<% 9 ????????????int rows = 10;10 ????????????int cols = 10;11 ????????????int count = 1;12 ????????????out.println("<table border=‘1‘ width=‘70%‘>");13 ????????????????for(int i=1;i<=rows;i++){14 ????????????????????out.println("<tr>");15 ????????????????????for(int j=1;j<=cols;j++){16 ????????????????????????out.println("<td>"+(count));17 ????????????????????????count++;18 ????????????????????}19 ????????????????????out.println("</tr>");20 ????????????????}21 ????????????22 ????????????out.println("</table>");23 ????????24 ????????%>25 ????????26 ????</body>27 </html>

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

 1 <!doctype html> 2 <html> 3 ????<head> 4 ????????<title>Table_out_jsp</title> ????????5 ????</head> 6 ????<body> 7 ????????????<table border=‘1‘ width=‘70%‘>; 8 ????????????????<% 9 ????????????????int rows = 10;10 ????????????????int cols = 10;11 ????????????????int count = 1;12 ????????????????for(int i=1;i<=rows;i++){13 ????????????????%>14 ????????????????????<tr>15 ????????????????????????<% 16 ????????????????????????for(int j=1;j<=cols;j++){ ??17 ????????????????????????%> ???18 ????????????????????????19 ????????????????????????<td>20 ????????????????????????????21 ????????????????????????????<%=(count)%>22 ????????????????????????</td>23 ????????????????????????????24 ????????????????????????<% 25 ????????????????????????????count++;26 ????????????????????????} 27 ????????????????????????%> ???28 ????????????????????????29 ????????????????????</tr>30 ????????????????<% 31 ????????????????} 32 ????????????????%>33 ????????????</table>34 ????????????35 ????????36 ????????37 ????????38 ????</body>39 </html>

JSP_01

原文地址:http://www.cnblogs.com/liuyangv/p/8034742.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved