当前位置: 首页 > 编程日记 > 正文

SpringMVC学习手册(三)------EL和JSTL(上)

1.含义

EL:       Expression Language , 表达式语言
JSTL:   Java Server Pages Standard Tag Library, JSP标准标签库

2.测试项目构建

2.1 复制JSTL的标准实现

复制Tomcat中webapps\examples\WEB-INF\lib下的两个jar包到新建项目目录的WEB-INF\lib下

2.2 在JSP文件中使用taglib标记定义前缀与uri引用

使用Core标签库:
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
使用Function标签库:
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
然后就可以在自己的JSP页面进行编写测试了

3.EL 学习

3.1 JSP页面的EL控制开关

EL表达式类似于JSP表达式<%=表达式%>,可以通过JSP页面的page指令的isELIgnore属性指明JSP页面是否支持EL表达式.
false:支持
true:不支持
JSP页面默认isELIgnore为false,也就是说一般用Eclipse建立的JSP页面可以直接使用EL表达式

3.2 基本语法的使用:

基本形式:
${EL 隐含对象.关键字对象.属性}

(1)"[]"与"."获取值

一般我们需要获取的值有三种形式:
  • JavaBean 中的值
  • 数组中的值
  • 集合中的值
下面我们通过一个JSP页面来测试这三种获取值的形式:
<%@page import="
java.util.*,
model.*
"%>
<%@ page language="java" contentType="text/html;  charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01  Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;  charset=UTF-8">
<title>Insert title here</title>
</head>
<body><%        //对象参数Student s= new Student("Tom",19);pageContext.setAttribute("ps", s);//数组参数int numList[]={1,2,3,4,5};pageContext.setAttribute("pnumList",numList);//List集合参数ArrayList<Integer> sList = new  ArrayList<Integer>();sList.add(1);sList.add(2);sList.add(3);pageContext.setAttribute("psList",sList);//Map集合参数Map<String,String> m =new HashMap<>();m.put("Tom", "19");m.put("Tina","20");pageContext.setAttribute("pm", m);%><div>1.取值操作<p>(1)获取student对象属性(个人觉得使用"."的形式获取更方便):</p><ul><li>${ps.name}</li><li>${ps.age}</li><li>${ps["name"]}</li><li>${ps["age"]}</li>             </ul><p>(2)获取数组中的值:</p><ul><li>${pnumList[0]}</li><li>${pnumList[1]}</li><li>${pnumList[2]}</li><li>${pnumList[3]}</li></ul>     <p>(3)获取List集合对象中的值:</p><ul><li>${psList[0]}</li><li>${psList[1]}</li><li>${psList[2]}</li></ul>         <p>(4)获取Map集合对象中的值,如果键为数值,只能使用"[]"形式获取其中的值</p><ul><li><span>Tom`s age:</span>${pm.Tom}</li><li><span>Tina`s  age:</span>${pm["Tina"]}</li></ul>     </div> </body>
</html>

(2)运算符

算数运算符:
符号示例结果
+${1+1}2
-${1-1}0
*${1*1}1
/ 或div${1 /1}1
% 或 mod${10 %3 }1
关系运算符:
符号:== 或 eq!= 或 ne< 或 lt> 或 gt<= 或 le>= 或 ge
逻辑运算符:
符号
&& 或 and
|| 或 or
! not
条件运算符:
符号(三目运算符)
?:
empty运算符:
用于检测一个值是否为null,例如变量A不存在,则${empty A} 返回的结果为True

3.3 EL隐含对象

  • pageScope
  • requestScope
  • sessionScope
  • applicationScope
其分别对应了JSP的隐含对象:
  • pageContext
  • request
  • session
  • application
注意如果一个EL表达式没有指定查找对象,其会依次从page,request,session,application中的范围中查找
  • 找到:直接返回,不再继续查出下去
  • 没找到:返回空字符串

3.4 EL与请求参数相关的隐含对象

主要用于JSP接受来自form的参数,相关对象为:param和paramValues,通过例子学习其 使用方法
input.jsp
<%@ page language="java" contentType="text/html;  charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01  Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;  charset=UTF-8">
<title>Insert title here</title>
</head>
<body><form method="post" action="param.jsp">名字:<input type="text" name="userName"/ ><input type="checkbox" name="habit" value="读书"/>读书<input type="checkbox" name="habit" value="游戏"/>游戏<input type="checkbox" name="habit" value="跑步"/>跑步<input type="submit" value="提交"/></form>
</body>
</html>

param.jsp
<%@ page language="java" contentType="text/html;  charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01  Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;  charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("UTF-8"); %>
${param.userName }
${paramValues.habit[0]}
${paramValues.habit[1]}
${paramValues.habit[2]}
</body>
</html>

附录:测试项目

源码下载:https://github.com/Taoey/cnblog-demos/releases/download/v1.0/JSTLTest.1.zip

转载于:https://www.cnblogs.com/hwtblog/p/8386630.html

相关文章:

OpenStack Heat模板详解

Heat模板全称为heat orchestration template&#xff0c;简称为HOT。 1 典型Heat模板结构 heat_template_version: 2015-04-30 description:# a description of the template parameter_groups:# a declaration of input parameter groups and order parameters:# declaration …

如何从头开始构建自己的Linux Dotfiles Manager

As a new linux &#x1f427; user, you might realize that there are a bunch of configuration files present in your system. These special files are called "dotfiles". 作为新的Linux用户&#xff0c;您可能会意识到系统中存在大量配置文件。 这些特殊文件…

D3.js、HTML5、canvas 开发专题

https://www.smartdraw.com/genogram/ http://www.mamicode.com/info-detail-1163777.html D3折线图 https://www.cnblogs.com/hwaggLee/p/5073885.html js-d3画图插件 http://www.xiaomlove.com/2014/06/29/d3-js简单画图-箭头连接随机圆圈/ 连线 http://www.decemberc…

单向链表JAVA代码

//单向链表类publicclassLinkList{ //结点类 publicclassNode{ publicObject data; publicNode next; publicNode(Object obj,Node next){ this.data obj; this.next next; } } Node head; //记录…

forkjoin rxjs_如何通过吃披萨来理解RxJS运算符:zip,forkJoin和Combine

forkjoin rxjs什么是RxJS&#xff1f; (What is RxJS?) Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change - Wikipedia响应式编程是一种与数据流和变更传播有关的异步编程范式 -Wikipedia RxJS is a…

SQLserver数据库操作帮助类SqlHelper

1 SqlHelper源码 using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collections; namespace SQL.Access {/// <summary>/// SqlServer数据访问帮助类/// </summary>public sealed class SqlHelper{#region 私有构造…

python框架之Flask基础篇(一)

一.第一个hello world程序 # codingutf-8 from flask import Flaskapp Flask(__name__)app.route(/) def hello_world():return Hello World!if __name__ __main__:app.run(debugTrue) 1.app参数的设置&#xff1a; 以下几种方式全部拿debug模式举例&#xff1a; .方式一&…

flask部署机器学习_如何开发端到端机器学习项目并使用Flask将其部署到Heroku

flask部署机器学习Theres one question I always get asked regarding Data Science:关于数据科学&#xff0c;我经常被问到一个问题&#xff1a; What is the best way to master Data Science? What will get me hired?掌握数据科学的最佳方法是什么&#xff1f; 什么会雇…

UVALive2678:Subsequence

UVALive2678:Subsequence 题目大意 给定一个数组A和一个整数S。求数组A中&#xff0c;连续且之和不小于S的连续子序列长度最小值。 要求复杂度:Ο(n) Solution 用变量L表示所选区间最左端下标&#xff0c;用变量R表示所选区间最右端下标&#xff0c;用变量sum表示所选区间的和。…

【BZOJ-3712】Fiolki LCA + 倍增 (idea题)

3712: [PA2014]Fiolki Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 303 Solved: 67[Submit][Status][Discuss]Description 化学家吉丽想要配置一种神奇的药水来拯救世界。吉丽有n种不同的液体物质&#xff0c;和n个药瓶&#xff08;均从1到n编号&#xff09;。初始时&am…

访问系统相册或调用摄像头

头文件&#xff1a;#import <MobileCoreServices/MobileCoreServices.h> 协议&#xff1a;<UINavigationControllerDelegate, UIImagePickerControllerDelegate> // 调用系统相册获取图片 - (IBAction)getImageFromAlbum:(id)sender {// 判断系统相册是否可用&…

unity镜像_通过镜像学习Unity Multiplayer Basics

unity镜像Unity is one of the most well-known and established engines for game development, and Mirror is a third-party, open source networking solution that allows you to add multiplayer to your games.Unity是最著名的游戏开发引擎之一&#xff0c;而Mirror是第…

java内存模型和线程安全

转载于:https://www.cnblogs.com/Michael2397/p/8397451.html

测试,发布,质量保障,用户体验

1.在实际项目中何时开始设计用户体验&#xff1a;用户的第一印象&#xff1b;从用户的角度考虑问题&#xff1b;软件啊服务始终要记住用户的选择&#xff1b;短期刺激和长期影响 2.测试经验交流&#xff1a;基本名词解释及分类&#xff1b;按测试设计的方法分类&#xff1b;按测…

UIImage存为本地文件与UIImage转换为NSData

UIImage *image"XXX"; //png格式 NSData *imagedataUIImagePNGRepresentation(image); //JEPG格式 //NSData *imagedataUIImageJEPGRepresentation(image); NSArray*pathsNSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString …

如何在JavaScript中实现链接列表

If you are learning data structures, a linked list is one data structure you should know. If you do not really understand it or how it is implemented in JavaScript, this article is here to help you. 如果您正在学习数据结构&#xff0c;则链表是您应该知道的一种…

SVG.path_不连续的线段

1、之前 用<path/>画的 线段等 都是连续的&#xff0c;想知道 是否能画 不连续的线段等 结论&#xff1a;可以 2、测试代码&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <svg width"1000" height"800" viewBo…

Leetcode 之Binary Tree Postorder Traversal(44)

后序遍历&#xff0c;比先序和中序都要复杂。访问一个结点前&#xff0c;需要先判断其右孩子是否被访问过。如果是&#xff0c;则可以访问该结点&#xff1b;否则&#xff0c;需要先处理右子树。 vector<int> postorderTraversal(TreeNode *root){vector<int> resu…

如何创建自己的ESLint配置包

ESLint is a powerful tool that helps you enforce consistent coding conventions and ensure quality in your JavaScript codebase. ESLint是一个功能强大的工具&#xff0c;可帮助您实施一致的编码约定并确保JavaScript代码库的质量。 Coding conventions are sometimes …

MySQL更新命令_UPDATE

创建测试表 mysql> CREATE TABLE product (-> proID int(11) NOT NULL AUTO_INCREMENT COMMENT 商品表主键,-> price decimal(10,2) NOT NULL COMMENT 商品价格,-> type int(11) NOT NULL COMMENT 商品类别(0生鲜,1食品,2生活),-> dtime datetime N…

KVC与KVO

1、键值编码KVC常用的KVC操作方法如下&#xff1a;• 动态设置&#xff1a; setValue:属性值 forKey:属性名&#xff08;用于简单路径&#xff09;、setValue:属性值 forKeyPath:属性路径&#xff08;用于复合路径&#xff0c;例如Person有一个Account类型的属性&#xff0c…

javaScript 工作必知(三) String .的方法从何而来?

String 我们知道javascript 包括&#xff1a;number&#xff0c;string&#xff0c;boolean,null,undefined 基本类型和Object 类型。 在我的认知中&#xff0c;方法属性应该是对象才可以具有的。 var str"hello,world";var sstr.subString(1,4);//ellalert(typeof…

s3 aws_您需要了解的有关AWS S3的所有信息

s3 awsThis article will provide an in-depth introduction to AWS S3 — the secure, scalable, and super cheap storage service from Amazon Web Services.本文将深入介绍AWS S3-来自Amazon Web Services的安全&#xff0c;可扩展和超便宜的存储服务。 If you have eve…

untitled与前端——初学

“前端” 啥&#xff1f; 百度百科&#xff1a; 就是制作一网页界面。比如360浏览器打开&#xff0c; 包括界面布局设计&#xff0c;搜索框&#xff0c;点击字或图标跳到另一个页面等。 软件Untitled 下载网址&#xff1a;http://www.jetbrains.com/ 下拉 点download&#xff0…

NSThread

NSThread是轻量级的多线程开发&#xff0c;使用起来也并不复杂&#xff0c;但是使用NSThread需要自己管理线程生命周期。 可以使用对象方法&#xff1a; (void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)argument 直接将操作添加到线程中并…

异步发送邮件、短信、微信

用户创建订单的按钮点击后&#xff0c;服务器存储这个订单信息后&#xff0c;调用发送短信、邮件、微信的接口&#xff0c;发送消息。而发送短信、邮件、微信都要涉及第三方的处理&#xff0c;服务器又要发送一个新的包裹给一个新的服务器&#xff0c;告诉他帮我发一个信息出去…

英语面试简短问题_用简单的英语解释产品设计

英语面试简短问题Product design is the process you go through when you conceptualize and build a product.产品设计是概念化和构建产品时要经历的过程。 The path to building – hardware, software, or even simple prototypes – has different steps and approaches.…

6-12 二叉搜索树的操作集

6-12 二叉搜索树的操作集&#xff08;30 分&#xff09; 本题要求实现给定二叉搜索树的5种常用操作。 函数接口定义&#xff1a; BinTree Insert( BinTree BST, ElementType X ); BinTree Delete( BinTree BST, ElementType X ); Position Find( BinTree BST, ElementType X );…

iOS关于自定义rightBarButtonItem

在常见iOS开发中,我们常遇到这样的需求,如下: 我们需要自定义导航栏右侧按钮,常见的自定义包装按钮如下: //设置rightItem; UIButton *btn [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame CGRectMake(0, 0, 40, 30); btn.selected NO; [btn setTitle:"管理&…

URL里汉字转码

URL里面不能包含中文。 解决办法&#xff1a;进行转码 NSString *urlStr[NSString stringWithFormat:kLotteryBar_putOutReviewUrl,_token,self.reviews_id,_User_Id,reviews_content]; urlStr[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];