jstl中怎么获取Parameter参数
今天就跟大家聊聊有关jstl中怎么获取Parameter参数,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
param 获取 Parameter参数<c:choose> <c:when test="${emptyparam.name}"> Please enter your name. </c:when> <c:otherwise> Hello <b><c:out value="${param.name}" /></b>! </c:otherwise></c:choose>
一般而言,我们在取得用户的请求参数时,可以利用下列方法:request.getParameter(String name)request.getParameterValues(String name)在EL中则可以使用param和paramValues两者来取得数据。${param.name}${paramValues.name}可以取得所有同名参数的值${paramValues.hobbies[0]}可以通过指定下标来访问特定的参数的值
获取访问路径
${pageContext.request.contextPath}
等同于
<%=request.getContextPath()%>
获取Session
${sessionScope.user.sex}
上述EL范例的意思是:从Session取得用户的性别。
如果使用之前JSP代码的写法如下:<%User user = (User)session.getAttribute(”user”);String sex = user.getSex( );%>
EL的隐含对象
EL也可以使用内置对象中设置的属性,需要使用特定的EL内置对象
属性范围 | 在EL中的对象
Page | pageScope
Request | requestScope
Session | sessionScope
Application | applicationScope
EL中使用内置对象的属性${requestScope.user}等价于<%request.getAttribute(”user”)%>如果不写出特定的范围 ,那就会在不同的范围间进行搜索了例:{user}(user是在request范围 request.setAttribute(”user”,user))也就等于${requestScope.user}<%request.getAttribute(”user”)%>
pageContext对象我们可以使用 ${pageContext}来取得其他有关用户要求或页面的详细信息。下面列出了几个比较常用的部分。Expression 说 明${pageContext.request} |取得请求对象${pageContext.session} |取得session对象${pageContext.request.queryString} |取得请求的参数字符串${pageContext.request.requestURL} |取得请求的URL,但不包括请求之参数字符串${pageContext.request.contextPath} |服务的web application的名称${pageContext.request.method} |取得HTTP的方法(GET、POST)${pageContext.request.protocol} |取得使用的协议(HTTP/1.1、HTTP/1.0)${pageContext.request.remoteUser} |取得用户名称${pageContext.request.remoteAddr } |取得用户的IP地址${pageContext.session.new} |判断session是否为新的,所谓新的session,表示刚由server产生而client尚未使用${pageContext.session.id} |取得session的ID${pageContext.servletContext.serverInfo}|取得主机端的服务信息
看完上述内容,你们对jstl中怎么获取Parameter参数有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注恰卡编程网行业资讯频道,感谢大家的支持。
推荐阅读
-
Web应用从零开始,初学者友好型开发教程
-
容器化最佳实践:Docker 与 Kubernetes 在微服务架构中的协同设计
-
AWS Cloud9 使用攻略:云端 IDE 如何无缝集成 Lambda 与 S3 服务?
-
Heroku vs AWS Elastic Beanstalk:快速部署 Web 应用的平台对比
-
Kubernetes 集群部署避坑:资源调度、服务发现与滚动更新策略
-
Docker 镜像优化指南:分层构建、瘦身技巧与多阶段编译实践
-
Postman 接口测试全流程:从 API 设计到自动化测试脚本编写
-
pytest 框架进阶:自定义 fixture、插件开发与持续集成集成方案
-
JUnit 5 新特性:参数化测试、扩展模型与微服务测试实践
-
Chrome DevTools 性能分析:FPS 监控、内存快照与网络请求优化指南