我有一个参数,比如 someVar ,可以通过 $ {someVar} 在jsp块中访问。我想知道如何在java代码块< %%>中获取此值。我试过了
<%
String str = request.getParameter("someVar");
%>
和str为null。如何在&lt; %%&gt;中获得 someVar 块?感谢。
答案 0 :(得分:0)
使用隐式对象 PageContext
以这种方式
<% Object obj = pageContext.getAttribute("someVar"); %>
或者这样
<% Object obj = pageContext.getAttribute("someVar",pageContext.SCOPE); %>
不同的范围是
pageScope it maps the given attribute name with the value set in the page scope
requestScope it maps the given attribute name with the value set in the request scope
sessionScope it maps the given attribute name with the value set in the session scope
applicationScope it maps the given attribute name with the value set in the application scope