zoukankan      html  css  js  c++  java
  • EL表达式学习(二)

    1.从特定域中获取值;

    2.从请求页面的input标签中,获取值;(同servlet中的getParameter和getParameterValues);

    3.获取请求头(同servlet中的getHeader和getHeaders);

    4.获取cookie和session;

    5.获取全局参数;


    前驱页面:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    	<form action="/JSP_Study/el_expression/04el.jsp">
    		name:<input name="name" type="text" value="aaa"/><br>
    		name:<input name="name" type="text" value="bbb"/><br>
    		<input type="submit" value="跳入04el.jsp"/>
    		
    	</form>
    </body>
    </html>

    测试El的JSP:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" isELIgnored="false" import="java.util.*, java.lang.*"%>
    <%
     		// 为什么我这儿加一个逻辑判断仍然不对?
     		boolean t = (request.getParameter("name") == null);
     		System.out.println(t);
    		if(request.getParameter("name") == null) {
    			/* request.getRequestDispatcher("04pre_04el.jsp").forward(request, response); */
    			/* response.sendRedirect("/el_expression/04pre_04el.jsp"); */
    			response.sendRedirect("/JSP_Study/el_expression/04pre_04el.jsp");  // 重定向是浏览器行为!!!
    		} else { // 此处必须写else :并发执行不然会出现空指针异常!!!
    		// 去理解jsp的生成过程,转化成.class文件的过程,是否是因为存在并发的执行操作。
    %> 
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>EL的11个内置对象</title>
    </head>
    <body>
    	
    	<%--
    	1) 1.pageContext  等价于 jsp中的pageContext内置对象
    	 --%>
    	 <%-- 获取上下文路径:此处的两种方式都可以,我熟悉的是通过servletContext来获取上下文路径;这里提供的request获得不太明白 --%>
    	 ${pageContext.servletContext.contextPath }<br>
    	 ${pageContext.request.contextPath }<br>
    	 <hr>
    	 
    	 <%--
    	 2.pageScope
    	 3.requestScope
    	 4.sessionScope
    	 5.applicationScope
    	 从指定的域中获取数据
    	  --%>
    	  
    	  <%--
    	  2) 6.param:获取参数
    	  	 7.paramValues:获取所有参数值
    	   --%>
    	   用JSP内置的request的getParameter获取的:<%=request.getParameter("name") %><br>
    	   用EL的param获取的:	${param['name'] }<br>
    	   用JSP内置的request的getParameterValues获取的:<%=request.getParameterValues("name")[1] %><br>
    	   用EL的paramValues获取的:${paramValues['name'][0] } -- ${paramValues['name'][1] }
    	 <hr>
    	  <%--
    	  3) 8.header:获取请求头
    	  	 9.headerValues
    	  类似上面的param和paramValues
    	   --%>
    	 JSP内置对象header获取:<%=request.getHeader("host") %><br>
    	 JSP内置对象headers获取:<%=request.getHeaders("host").nextElement() %><br>   
    	 EL内置对象header获取:${header['host'] }<br>
    	 EL内置对象headerValues获取:${headerValues['host'][0] }
    	 <hr>
    	 
    	  <%--
           	4)10.cookie: 获取cookie
          --%>
          <hr/>
          <%=request.getCookies()[0].getValue() %><br/>
          ${cookie['JSESSIONID'].name } - ${cookie['JSESSIONID'].value }
          <hr/>
          
          <%--
          5)11.initParam: 获取全局参数
          --%>
           <%=application.getInitParameter("AAA") %><br/>
           ${initParam['AAA'] }
    </body>
    </html>
    <%} %>

  • 相关阅读:
    spring cloud 和 阿里微服务spring cloud Alibaba
    为WPF中的ContentControl设置背景色
    java RSA 解密
    java OA系统 自定义表单 流程审批 电子印章 手写文字识别 电子签名 即时通讯
    Hystrix 配置参数全解析
    spring cloud 2020 gateway 报错503
    Spring Boot 配置 Quartz 定时任务
    Mybatis 整合 ehcache缓存
    Springboot 整合阿里数据库连接池 druid
    java OA系统 自定义表单 流程审批 电子印章 手写文字识别 电子签名 即时通讯
  • 原文地址:https://www.cnblogs.com/mzywucai/p/11053508.html
Copyright © 2011-2022 走看看