JSP中正则表达式用法实例

本文实例讲述了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+"/";
%>


 
 
 My JSP 'El.jsp' starting page
 
 
  
 
 
 
 
 
 <%
  String data="assd";
  request.setAttribute("data", data);
 %>
 
 ${data }
 
<% Person p=new Person(); p.setName("name"); request.setAttribute("person", p); %> ${person.name}
<% Person p2=new Person(); Adddress add=new Adddress(); add.setCity("NewYork"); p2.setAddress(add); request.setAttribute("p2", p2); %> ${p2.address.city}
<% 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 }
<% 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.b.name} ${map['1'].name }
${pageContext.request.contextPath}

PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript

正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg

希望本文所述对大家JSP程序设计有所帮助。

你可能感兴趣的:(JSP中正则表达式用法实例)