关于EL表达式中requestScope和param区别
来源:互联网 发布:淘宝禁售商品答案 编辑:程序博客网 时间:2024/06/05 06:31
<body> ${test}
${requestScope.test}<%request.getAttribute("test"); %></body>
以上代码均不能取出值
仅当 使用<% request.setAttribute("test", "123"); %>赋值时<body/>内可以正常取出值
那么如何取出URL 中的test 的值呢?如下
<body> ${param.test}<%=request.getParameter("test") %></body>均可取出URL中的test的值。。
结论:${param.name} 等价于 request.getParamter("name"),这两种方法一般用于服务器从页面或者客户端获取的内容。
${requestScope.name} 等价于 request.getAttribute("name"),一般是从服务器传递结果到页面,在页面中取出服务器保存的值。
今天演示EL表达式的时候发现自己jsp的基础实在是薄弱,在这个很简单的问题上迷惑了很久。
首先在看遇到的问题:
在浏览器地址输入,表示传入一个参数test,值为123
http://localhost:8888/Test/index.jsp?test=123
在index.jsp中尝试使用EL表达式取出,代码如下:
<body> ${test} </body>
发现毫无结果,再使用requestScope尝试取出:
<body> ${requestScope.test} </body>
发现还是毫无结果,感到非常诧异,遂干脆使用java脚本尝试取出。
<body> <%request.getAttribute("test"); %> </body>
依然无解。
之后发现,若使用已下代码向request作用域赋值,则用上面代码可以取出
<% request.setAttribute("test", "123"); %>
查询资料后发现,使用以下代码可以取出之前的请求参数:
EL:
<body> ${param.test} </body>
JAVA脚本:
<body> <%=request.getParameter("test") %> </body>
结论就是:${param.name} 等价于 request.getParamter("name"),这两种方法一般用于服务器从页面或者客户端获取的内容。
${requestScope.name} 等价于 request.getAttribute("name"),一般是从服务器传递结果到页面,在页面中取出服务器保存的值。
阅读全文
0 0
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 10029---关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别
- 关于EL表达式中requestScope和param区别,el表达式与jstl标签
- 关于EL表达式中requestScope和param区别,el表达式与jstl标签
- EL表达式页面传值(${param}和requestScope)
- J2EE中getParameter与getAttribute以及EL表达式${requestScope}和${param[]}
- J2EE中getParameter与getAttribute以及EL表达式${requestScope}和${param[]}
- 【最大流 && 拆点限流】POJ
- response.setCharacterEncoding("UTF-8")不生效的原因及解决方法
- 散列表(下)——分离链接法
- adb无法识别安卓设备
- kotlin学习之旅
- 关于EL表达式中requestScope和param区别
- eclipse 摁住ctrl 键卡死
- Python模块在linux服务器上的下载安装(无sudo权限)
- Java:程序执行流程+命令行获取命令
- File对象
- Python初学笔记-继承
- Struts2-03-拦截器(BOS物流项目用户登录拦截)
- JZOJ 5376. 【NOIP2017提高A组模拟9.19】Candy
- Relevant Phrases of Annihilation SPOJ