How do I get hold of the HttpServletRequest
HttpServletRequest request = ServletActionContext.getRequest();
if (request != null)
{
// do something here
}
You should always assume that ServletActionContext.getRequest() will return null. ServletActionContext is only populated if the request comes in through WebWork. There are a number of circumstances in which it will not be populated, either because a web request has come in through some other path, or because there was no web request in the first place:
* AJAX requests that come in via the DWR servlet
* SOAP/XML-RPC requests
* Scheduled tasks, including the sending of email notifications
Treat ServletActionContext as a bonus. If it’s populated you can do neat things with it, but don’t rely on it.
源自:http://confluence.atlassian.com/pages/viewpage.action?pageId=157451
上面的说的是WEBWORK.既然struts2以webwork为核心,应该也适用于struts2。
你好,
前两天我做项目时,碰到了从页面传值(user.action?parentId=2)到action中到,
得不到parentId的值,并且request 为null.热切希望得到你的回答。