(Struts2)OGNL笔记 # 的用法一

可以用#访问 Request, Session, Application 等

 

Action

    public String execute() {
        // set value into session
        ActionContext.getContext().getSession().put("key", "session scope value");

        // set value into request
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("key", "request scope value");

        return SUCCESS;
    }

JSP

	<h2>
		<s:property value="#session.key" />
	</h2>
	<h2>
		<s:property value="#request.key" />
	</h2>

结果如下:

    session scope value
    request scope value

 

 

你可能感兴趣的:(jsp)