正则表达式JSP实例

前端之家收集整理的这篇文章主要介绍了正则表达式JSP实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. <%@ page language="java" import="java.util.*,cn.com.Person,cn.com.Adddress" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6.  
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  8. <html>
  9. <head>
  10. <base href="<%=basePath%>">
  11. <title>My JSP 'El.jsp' starting page</title>
  12. <Meta http-equiv="pragma" content="no-cache">
  13. <Meta http-equiv="cache-control" content="no-cache">
  14. <Meta http-equiv="expires" content="0">
  15. <Meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  16. <Meta http-equiv="description" content="This is my page">
  17. <!--
  18. <link rel="stylesheet" type="text/css" href="styles.css">
  19. -->
  20.  
  21. </head>
  22. <body>
  23. <%
  24. String data="assd";
  25. request.setAttribute("data",data);
  26. %>
  27. <!-- 正则表达式,对于 Request传过来的数据可以直接如下显示
  28. 相当于:pageContext.findAttribute("data");
  29. 这是一般的方式
  30. -->
  31. ${data }
  32. <br/>
  33. <%
  34. Person p=new Person();
  35. p.setName("name");
  36. request.setAttribute("person",p);
  37. %>
  38. <!-- 反射name属性获取这个值输出
  39. 数据通过JAVABean里传过来的如下:
  40. -->
  41. ${person.name}
  42. <br/>
  43. <%
  44. Person p2=new Person();
  45. Adddress add=new Adddress();
  46. add.setCity("NewYork");
  47. p2.setAddress(add);
  48. request.setAttribute("p2",p2);
  49. %>
  50. <!-- 下面的是定义一个Person的类和一个Adddress的类
  51. Person中私有属性:private Adddress address;
  52. 获取他的地址可以如下的方式来完成
  53. 数据复杂的bean里面带过来的如下:
  54. -->
  55. ${p2.address.city}
  56. <br/>
  57. <%
  58. ArrayList list=new ArrayList();
  59. list.add(new Person("wy"));
  60. list.add(new Person("wyy"));
  61. list.add(new Person("wyyy"));
  62. request.setAttribute("list",list);
  63. %>
  64. <!-- 集合带过来的怎么获取数据呢? -->
  65. ${list[1].name }
  66. <br/>
  67. <%
  68. Map map=new HashMap();
  69. map.put("1",new Person("aaaa"));
  70. map.put("b",new Person("bbbb"));
  71. map.put("c",new Person("cccc"));
  72. map.put("d",new Person("dddd"));
  73. request.setAttribute("map",map);
  74. %>
  75. <!--
  76. Map集合带过来的怎么获取数据呢?
  77. map集合的数据存放的时候id一般不要用数字:会出现500错误
  78. 但是用数字的话获取方式如第二条
  79. .号取不出来就用中括号[]
  80. -->
  81. ${map.b.name}
  82. ${map['1'].name }
  83. <br/>
  84. <!-- 获取当前的web项目名 -->
  85. ${pageContext.request.contextPath}
  86. <a href="${pageContext.request.contextPath}/demo1.jsp" ></a>
  87. </body>
  88. </html>

猜你在找的正则表达式相关文章