SpringMVC学习手册(三)------EL和JSTL(上)
1.含义
2.测试项目构建
2.1 复制JSTL的标准实现
2.2 在JSP文件中使用taglib标记定义前缀与uri引用
3.EL 学习
3.1 JSP页面的EL控制开关
3.2 基本语法的使用:
(1)"[]"与"."获取值
- JavaBean 中的值
- 数组中的值
- 集合中的值
<%@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 |
| 符号(三目运算符) |
| ?: |
3.3 EL隐含对象
- pageScope
- requestScope
- sessionScope
- applicationScope
- pageContext
- request
- session
- application
- 找到:直接返回,不再继续查出下去
- 没找到:返回空字符串
3.4 EL与请求参数相关的隐含对象
<%@ 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>
<%@ 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>

SpringMVC学习手册(三)------EL和JSTL(上)的更多相关文章
- Java Web学习笔记之---EL和JSTL
Java Web学习笔记之---EL和JSTL (一)EL (1)EL作用 Expression Language(表达式语言),目的是代替JSP页面中复杂的代码 (2)EL表达式 ${变量名} ( ...
- SpringMVC 学习笔记(三)数据的校验
34. 尚硅谷_佟刚_SpringMVC_数据绑定流程分析.avi 例如:在jsp中输入一个String字符串类型,需要转换成Date类型的流程如下 convertservice对传入的数据进行转换 ...
- SpringMVC学习笔记(三)
一.SpringMVC使用注解完成 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--configure the setti ...
- springmvc学习(三)
第一点---------使用 @RequestMapping 映射请求• Ant 风格资源地址支持 3 种匹配符:?:匹配文件名中的一个字符 *:匹配文件名中的任意字符 **:** 匹配多层路径 @R ...
- SpringMVC学习记录三——8 springmvc和mybatis整合
8 springmvc和mybatis整合 8.1 需求 使用springmvc和mybatis完成商品列表查询. 8.2 整合思路 springmvc+mybaits的 ...
- SpringMVC学习笔记三:Controller的返回值
springMVC的返回值有ModelAndView,String,void,Object类型 项目目录树: 该项目是在前面项目的基础上修改的,这里的pom.xml文件需要加入使用到的包,应为@Res ...
- springmvc学习日志三
一.文件的上传 1.首先在lib中添加相应的jar包 2.建立jsp页面,表单必须是post提交,编码必须是multipart/form-data,文件上传文本框必须起名 <body> & ...
- SpringMVC学习(三)整合SpringMVC和MyBatis
工程结构 导入jar包 配置文件 applicationContext-dao.xml---配置数据源.SqlSessionFactory.mapper扫描器 applicationContext-s ...
- springmvc学习第三天
利用spring mvc 实现crud 1.导入jar包 commons-logging-1.2.jarjstl.jarspring-aop-4.1.6.RELEASE.jarspring-beans ...
随机推荐
- #WEB安全基础 : HTML/CSS | 0x7HTML5和W3C验证
标准,标准,什么都有标准 你听说过HTML5吗?这是一个新版本,当然也有新标准 我只准备了一个index.html文件 以下是代码 <!DOCTYPE html> <!--告诉浏览器 ...
- Webpack4教程:第一部分,入口、输入和ES6模块
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://wanago.io/2018/07/16/webpack-4-course-par ...
- 调用android的getColor()方法出现 java.lang.NoSuchMethodError: android.content.res.Resources.getColor
1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor或者 java.lang.NoSuch ...
- SC命令
描述: SC 是用来与服务控制管理器和服务进行通信 的命令行程序. 用法: sc <server> [command] [service n ...
- leaflet动态路径
在leaflet中使用动态路径需要结合插件使用,对比了好几个插件,最终找到leaflet.motion比较合适: leaflet地址:https://leafletjs.com/ leaflet.mo ...
- SourceTree下载bitbucket代码
SourceTree安装方法 下载地址:https://www.sourcetreeapp.com/ 列几个安装过程中的注意点: 根URL(Root URL):https://bitbucket.or ...
- python3字符串格式化format()函数的简单用法
format()函数 """ 测试 format()函数 """ def testFormat(): # format()函数中有几个元素, ...
- ATL右键文件菜单
自己写的小程序中用到的,网上资料相对还是毕竟全的,这里再整理下.毕竟我也不是很了解ATL,里面估计还是有不少问题的,就当作参考吧. 1.创建ATL工程,这个没什么好讲的. 我对COM组件没什么研究,这 ...
- Windows 下安装drozer(Windows 10),连接手机(红米note4X)
Windows 下安装drozer(Windows 10),连接手机(红米note4X) 首先下载drozer(http://mwr.to/drozer). 红米手机开发者模式 遇到第一个问题,红米手 ...
- MPLAB X IDE调试仿真功能简单入门
仿真分为硬件仿真和软件仿真,这里的硬件仿真和软件仿真的区别,就不多说了,相信大家都听说过这两个概念. 我这里想给大家介绍的是“Set PC at Cursor”--“设置PC到光标处”这个功能,这个功 ...