JSP中正则表达式用法实例
程序员文章站
2023-01-25 15:33:45
本文实例讲述了jsp中正则表达式用法。分享给大家供大家参考,具体如下:
<%@ page language="java" import="java.util...
本文实例讲述了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正则表达式在线测试工具:
正则表达式在线生成工具:
希望本文所述对大家jsp程序设计有所帮助。
上一篇: 如何成为一名优秀的C程序员
下一篇: 第三次打卡,异常处理