无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了JSP中正则表达式用法。分享给大家供大家参考,具体如下:
<%@ page language="java" import="java.util.*,cn.com.Person,cn.com.Adddress" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'El.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String data="assd"; request.setAttribute("data", data); %> <!-- 正则表达式,对于 Request传过来的数据可以直接如下显示 相当于:pageContext.findAttribute("data"); 这是一般的方式 --> ${data } <br/> <% Person p=new Person(); p.setName("name"); request.setAttribute("person", p); %> <!-- 反射name属性获取这个值输出 数据通过JAVABean里传过来的如下: --> ${person.name} <br/> <% Person p2=new Person(); Adddress add=new Adddress(); add.setCity("NewYork"); p2.setAddress(add); request.setAttribute("p2", p2); %> <!-- 下面的是定义一个Person的类和一个Adddress的类 Person中私有属性:private Adddress address; 要获取他的地址可以如下的方式来完成 数据复杂的bean里面带过来的如下: --> ${p2.address.city} <br/> <% ArrayList list=new ArrayList(); list.add(new Person("wy")); list.add(new Person("wyy")); list.add(new Person("wyyy")); request.setAttribute("list", list); %> <!-- 集合带过来的怎么获取数据呢? --> ${list[1].name } <br/> <% Map map=new HashMap(); map.put("1", new Person("aaaa")); map.put("b", new Person("bbbb")); map.put("c", new Person("cccc")); map.put("d", new Person("dddd")); request.setAttribute("map", map); %> <!-- Map集合带过来的怎么获取数据呢? map集合的数据存放的时候id一般不要用数字:会出现500错误 但是用数字的话获取方式如第二条 .号取不出来就用中括号[] --> ${map.b.name} ${map['1'].name } <br/> <!-- 获取当前的web项目名 --> ${pageContext.request.contextPath} <a href="${pageContext.request.contextPath}/demo1.jsp" >点</a> </body> </html>
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家JSP程序设计有所帮助。
标签:
JSP,正则表达式
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《幸福工厂》无限报错解决方法
- 交错战线原始交易所推荐角色一览
- 战锤40K星际战士2战术职业介绍|战术职业技能效果一览
- 战锤40K星际战士2突击职业介绍|突击职业技能效果一览
- [妙音金曲]群星《悲情咖啡屋》(黑胶)2CD[DTS-WAV]
- 阿兰·达瓦卓玛《A-Lan阿兰唯美歌姬》2CD[DTS-WAV]
- 【小提琴】陈立新《思乡曲》2004[FLAC+CUE]
- 《战地》新作明年初大规模测试!EA已内部测试一年
- 《GTAOL》PC版时隔多年更新反作弊!小助手宣布跑路
- EA称AI是其业务核心!能提高开发效率、节约成本
- 卫华.1990-太阳升【BMG】【WAV+CUE】
- 呼吸乐队.1992-THEBREATHING【深飞】【WAV+CUE】
- 李玟.2008-1994-2008豪华典藏精选2CD【SONY】【WAV+CUE】
- 《张学友 再现歌神的光辉岁月 梦想成真 2CD》[WAV/分轨][1.2GB]
- 《海来阿木 高音测试王》[WAV+CUE][500MB]