How can Action class will get access to HttpServletRequest to access data??
RaviNada Kiran
Ranch Hand
Joined: Jan 30, 2009
Posts: 528
posted
0
Please help me understand this .I am completely new to struts2 version .
I am referring to tutorials but couldn't get this concept. Posted so that i can get help here .
How can Action class will get access to HttpServletRequest to access data??
class NewAction {
public void String execute() throws Exception {
if ( its-ok() ) {
return "login";
}
else {
return "none";
}}}
If you want something you never had do something which you had never done
In general Struts 2 abstracts the request away; the framework populates action properties from request parameters. Assuming the form:the action would just define a "name" property--no need to access the request:You can access request parameters through a map by implementing ParameterAware if really necessary, but it's usually not.
You can access the HttpServletRequest itself by either implementing ServletRequestAware or using the ServletActionContext static utils. It's relatively rare to need to do either of these, and for obvious reasons it's not recommended.
RaviNada Kiran
Ranch Hand
Joined: Jan 30, 2009
Posts: 528
posted
0
Thanks sonny and David for your replies.
I doesn't want to extend the ActionSuppourt class to get access to the data .I want to go with the ServletRequestAware interface only.
so for this can i do directly like this ??
A single class is sufficient or do i need to use anyother class ??
The code I provided above is the canonical (normal, usual) way to get at form/request data in Struts 2.
You don't *have* to extend ActionSupport, but you'd have to convince me there's a good reason not to--it provides the validation and localization support needed by nearly any web application.
As Dave is saying, things are done differently in Struts 2, and for good reasons.
I suggest that you do some more reading on Struts 2 basics.
A good start will be the tutorial and other resources at http://www.struts2.net/.
There is also a free book available at InfoQ - Starting Struts 2.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How can Action class will get access to HttpServletRequest to access data??