el(表达式语言中)可以使用pageContext来间接访问JSP的内置对象,比如检索请求的方法,${pageContext.request.method}
我想问的是,假如有个java代码是
<jsp:useBean id="someid" scope="request" class="somePackage.someClass"/>
那么根据我的理解,就是将一个名字叫someid的bean 实例,将其添加到了request作用域中,也就是相当调用了request.setAttribute("someid",所有bean信息);
则如果我要在el表达式中访问这个bean的属性(假如有个属性 String someAttribute)
那么应该要用 ${requestScope.someId.someAttribute}呢,还是${pageContext.request.someId.someAttribute}?
9 个解决方案
#1
${someId}
这样就行,默认是requestScope
这样就行,默认是requestScope
#2
我知道这样可以,我只是想学习的更加深刻一点而已,找到pageContext.request和requestScope这2个之间的区别而已。呵呵
#3
应该用${requestScope.someId.someAttribute}
#4
pageContext.request.method实际上是调用request类中的getMethod方法
而在HttpServletRequest类中实际上是没有一个叫getSomeId的方法,所以
${pageContext.request.someId.someAttribute}不行
而在HttpServletRequest类中实际上是没有一个叫getSomeId的方法,所以
${pageContext.request.someId.someAttribute}不行
#5
你可以试一下,用${pageContext.request.method}获得值
与request.getMethod()获得的值是一样的。
request中还有很多方法,比如request.getContextPath()
你也可以通过$(pageContext.request.contextPath)获取
但是通过requestScope.contextPath是获取不了的
requestScope只是将setAttibute方法保存的值获取出来。
大概就是这样的
与request.getMethod()获得的值是一样的。
request中还有很多方法,比如request.getContextPath()
你也可以通过$(pageContext.request.contextPath)获取
但是通过requestScope.contextPath是获取不了的
requestScope只是将setAttibute方法保存的值获取出来。
大概就是这样的
#6
学习了~
#7
已经明白了,谢谢各位
#8








#9
好东东
#1
${someId}
这样就行,默认是requestScope
这样就行,默认是requestScope
#2
我知道这样可以,我只是想学习的更加深刻一点而已,找到pageContext.request和requestScope这2个之间的区别而已。呵呵
#3
应该用${requestScope.someId.someAttribute}
#4
pageContext.request.method实际上是调用request类中的getMethod方法
而在HttpServletRequest类中实际上是没有一个叫getSomeId的方法,所以
${pageContext.request.someId.someAttribute}不行
而在HttpServletRequest类中实际上是没有一个叫getSomeId的方法,所以
${pageContext.request.someId.someAttribute}不行
#5
你可以试一下,用${pageContext.request.method}获得值
与request.getMethod()获得的值是一样的。
request中还有很多方法,比如request.getContextPath()
你也可以通过$(pageContext.request.contextPath)获取
但是通过requestScope.contextPath是获取不了的
requestScope只是将setAttibute方法保存的值获取出来。
大概就是这样的
与request.getMethod()获得的值是一样的。
request中还有很多方法,比如request.getContextPath()
你也可以通过$(pageContext.request.contextPath)获取
但是通过requestScope.contextPath是获取不了的
requestScope只是将setAttibute方法保存的值获取出来。
大概就是这样的
#6
学习了~
#7
已经明白了,谢谢各位
#8








#9
好东东