加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式JSP实例

发布时间:2020-12-14 02:07:26 所属栏目:百科 来源:网络整理
导读:%@ 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+"/
<%@ 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读