手机
当前位置:查字典教程网 >编程开发 >JSP教程 >JSP中正则表达式用法实例
JSP中正则表达式用法实例
摘要:本文实例讲述了JSP中正则表达式用法。分享给大家供大家参考,具体如下:MyJSP'El.jsp'startingpage${data}${p...

本文实例讲述了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/> <> ${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中正则表达式用法实例】相关文章:

JSP 重置按钮清空传入的表单数据实例

JScript中正则表达式用法详解

JSP分页显示如何实现

jsp中使用javabean实例

JSP 重置按钮清空传入的表单数据实例

JSP:重置按钮清空传入的表单数据实例

JSP培训之购物车实例

JSP语法大全及实例解析

JSP EL表达式详细介绍

JSP中图片验证是如何实现

精品推荐
分类导航