最近调试老工程的jsp代码,总被一些标签弄得很头大,比如${param.xxx},这样的参数在后台controller里找不到,前台又的确有值,不知道是从哪里来的,下面的文章解答了我的困惑。

转载自http://blog.csdn.net/ping159/article/details/6945031

•          与作用范围有关的EL隐含对象包含有:pageScope、requestScope、sessionScope和applicationScope

–        它们可以读取使用JSP内置对象pageContext、request、session以及application的setAttribute()方法所设定的对象的数值-----即getAttribute(String name),却不能取得其他相关信息。

–        例如,要取得session中储存的一个username属性的值,可以利用下面的方法:session.getAttribute("username")

–        在EL中则使用下面的方法:${sessionScope.username}

注意:如果没有设定使用EL内置对象的作用范围,则按照pageScope、requestScope、sessionScope和applicationScope的先后顺序读取属性值。

即,通知JSP引擎调用pageContext.findAttribute()方法,以标识符为关键字从各个域对象中获取对象。如果域对象中不存在标识符所对应的对象,则返回结果为“”(注意,不是null)。

•          与输入有关的隐含对象有两个,即param和paramValues,它们是EL中比较特别的隐含对象。例如,要取得用户的请求参数时,可以利用下列方法:

–        request.getParameter(String name)

–        request.getParameterValues(String name)

•          在EL中则可以使用param和paramValues两者来取得数据:

–        ${param.name}

–        ${paramValues.name

•          cookie

–        用来取得使用者的cookie值,例如在cookie中设定了username属性值,可以使用${cookie.username.value}来取得属性值。

•          header和headerValues

–        读取请求的头数据,使用header或headerValues内置对象,例如${header[“User-Agent”]},headerValues则用来取得所有的头信息,等价于调用request.getHeaders()方法。

•          initParam

–        initParam用来读取设置在web.xml中的参数值。例如${initParam.repeat},等价于:(String)application.getInitParameter(“repeat”);  或
servletContext.getInitParameter(“repeat”);

•          pageContext

–        pageContext用于取得其他有关用户要求或页面的详细信息

${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 是否为新的

${pageContext.session.id}               取得session 的ID

${pageContext.servletContext.serverInfo}   取得主机端的服务信息

实例:elScope.jsp页面,该页面主要用于演示EL表达式的隐式对象的使用。