实例解析JSP中EL表达式的各种运用(2)

<!DOCTYPE html> <html> <head> <title>用户表单</title> </head> <body> <form action="UserDemo.jsp" method="post"> 用户名:<input type="text" /><br /> 密码:<input type="password" /><br /> 姓名:<input type="text" /><br /> 性别:<input type="radio" value="男">男<input type="radio" value="女">女<br /> 爱好:<br /> <input type="checkbox" value="打篮球">打篮球<br /> <input type="checkbox" value="看书">看书<br /> <input type="checkbox" value="旅行">旅行<br /> <input type="checkbox" value="编程">编程<br /> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html> <!DOCTYPE html> <html> <head> <title>接收用户参数</title> </head> <body> <% //设置页面编码格式 request.setCharacterEncoding("gb2312"); %> <%--接收用户参数--%> 用户名:${<span>param</span>.username}<br /> 密码:${<span>param</span>.password}<br /> 姓名:${<span>param</span>.name}<br /> 性别:${<span>param</span>.sex}<br /> 爱好:${<span>paramValues</span>.interest[0]} ${<span>paramValues</span>.interest[1]} </body> </html>

cookie内置对象

<!DOCTYPE html> <html> <head> <title>设置cookie的值</title> </head> <body> <% //设置cookie的值 Cookie c = new Cookie("username","root"); //添加cookie到客户端 response.addCookie(c); %> <a href="https://www.jb51.net/getCookieDemo.jsp">显示cookie的值</a> </body> </html> <span><%@page language="java" contentType="text/html;charset=gb2312"%> <!DOCTYPE html> <html> <head> <title>取得cookie的值</title> </head> <body> cookie中的username的值为:${cookie.username.value} </body> </html>

header内置对象

<!DOCTYPE html> <html> <head> <title>取得header的值</title> </head> <body> ${header["host"]}<br /> ${header["user-agent"]}<br /> </body> </html>

initParam内置对象:获取web站点中设置的环境变量

<%@page language="java" contentType="text/html;charset=gb2312"%> <!DOCTYPE html> <html> <head> <title>获得环境参数</title> </head> <body> username参数值:${initParam.username}<br /> </body> </html> <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee " version="2.5"> <context-param> <param-name>username</param-name> <param-value>Zhangdapeng</param-value> </context-param> </web-app>

pageContex内置对象
用来取得有关用户请求和页面的详细信息

<%@page language="java" contentType="text/html;charset=gb2312"%> <!DOCTYPE html> <html> <head> <title>pageContext演示</title> </head> <body> <table> <tr> <td>取得请求的参数的字符串</td> <td>${pageContext.request.queryString}</td> </tr><tr> <td>取得请求URL</td> <td>${pageContext.request.requestURL}</td> </tr><tr> <td>取得web应用名称</td> <td>${pageContext.request.contextPath}</td> </tr><tr> <td>取得HTTP请求方式(POST/GET)</td> <td>${pageContext.request.method}</td> </tr><tr> <td>取得使用的协议</td> <td>${pageContext.request.protocol}</td> </tr><tr> <td>取得用户IP地址</td> <td>${pageContext.request.remoteAddr}</td> </tr><tr> <td>判断session是否为新</td> <td>${pageContext.session.new}</td> </tr><tr> <td>取得session的id</td> <td>${pageContext.session.id}</td> </tr> </table> </body> </html>

EL存取器:
使用存取器读取JavaBean中的数据

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjpyj.html