Struts2:Struts2在jsp中使用标签时值的获取

OGNL的使用中,需要访问一系列的对象,这些对象放在OGNLcontext中,context是一个Map结构,实际上它和ActionContext是相应的。

当用户发送请求时,struts会创建ActionContextValueStackaction对象,action对象放在ValueStack对象中,ValueStatck放在ActionContext中。










其中,ValusStackOGNLcontext对象的根对象。因此在JSP页面访问ValueStack内的属性时不需要“#”,而访问context的其他属性(如request)时必须使用“#”。

context除了ValueStack对象以外,还有以下对象:

  1. Parameters:用于访问HTTP请求参数,如#parameters['id']#parameters.id,相当于HttpServletRequest.getParameter()方法。
  2. Request:用于访问HTTP请求属性,如#request['user']#request.user,相当于HttpServletRequest.getAttribute()方法。
  3. Session:用于访问session属性。如:#session['user']#session.user,,相当于HttpSession.getAttribute()方法。
  4. Application:用于访问application属性。#application['user']#application.user,,相当于ServletContext.getAttribute()方法。
  5. Attr:比如直接获取user属性“#user”,如果PageContext可用,则访问PageContext,否则一次搜索requestsessionapplication对象。
posted @ 2016-11-16 19:52  且听风吟-wuchao  阅读(342)  评论(0)    收藏  举报