Child pages
  • Application, Session, Request objects in vm
Skip to end of metadata
Go to start of metadata

To get parameters from the QueryString or from a POSTed form, do not use getAttribute, use:


But that's quite obvious, since $req is the request object and we all know how it works.



session.setAttribute("sessionFoo", "sessionBar");
session.getServletContext().setAttribute("applicationFoo", "applicationBar");

<p>The following information should be available when sending the form below:

	<li>Request parameter 'querystringFoo' with value 'querystringBar';</li>
	<li>Request parameter 'formFoo' with value 'formBar';</li>
	<li>Session attribute 'sessionFoo' with value 'sessionBar';</li>
	<li>Application attribute 'applicationFoo' with value 'applicationBar'.</li>

<form action="test.vm?querystringFoo=querystringBar" method="post">
<input type="hidden" name="formFoo" value="formBar">
<p><input type="submit" value="Test!"></p>



#set ($ses = $req.getSession())
#set ($app = $ses.getServletContext())

<p>applicationFoo = $!app.getAttribute("applicationFoo") <code>(app.getAttribute("applicationFoo"))</code></p>
<p>sessionFoo = $!ses.getAttribute("sessionFoo") <code>(ses.getAttribute("sessionFoo"))</code></p>
<p>formFoo = $!req.getParameter("formFoo") <code>(req.getParameter("formFoo"))</code></p>
<p>querystringFoo = $!req.getParameter("querystringFoo") <code>(req.getParameter("queryStringFoo"))</code></p>

  • No labels


  1. Anonymous

    How do I set a request scoped object in an Interceptor and access it from a Velocity template?

    I've tried every combination and find it too difficult to switch from Struts and Servlets to Webwork. The documentation could include a section which describes the application, session and request scopes in more detail. Three lines of documentation is not enough.

  2. Anonymous

    This does not work. Should it?

    ActionContext.getContext().put("keyx", "valuex");


  3. Anonymous

    Found the problem. I have to put # in front of the key.


  4. From the JavaDocs of the class com.opensymphony.webwork.views.velocity.VelocityManager

    This method is responsible for creating the standard VelocityContext used by all WW2 velocity views. The following context parameters are defined:

    • req - the current HttpServletRequest
    • res - the current HttpServletResponse
    • stack - the current OgnlValueStack
    • ognl - an OgnlTool
    • webwork - an instance of WebWorkUtil
    • action - the current WebWork action