wood burning stoves 2.0*
The moose likes Struts and the fly likes Need help to understand the ActionServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need help to understand the ActionServlet" Watch "Need help to understand the ActionServlet" New topic
Author

Need help to understand the ActionServlet

dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Friends,

I am new to Struts framework. I have been going through the text "Struts in Action" for a while. In one of the sample application there are two classes,

RegisterForm.java


RegisterAction.java


My understanding is the RegisterForm.java is the Model in which the input form data is being populated and the RegisterAction.java is the Action class that implements the business logic. But i dont understand which acts as the "Controller". The text says that the Controller invokes the action.

Can anybody help me? All the help will be hugely appreciated.
Sorry if i have not formed my query properly.
Thanks in advance!!!
dinesh.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi dinesh

The FormClass(RegisterForm.java) is a java bean(POJO). Controller is framework(along with struts-config) which calls the ActionClass(RegisterAction.java).
Actionclass- may/maynot have the business logic in it. As per stds and best practices it should not contain any business logic. It should just act as a place where you direct the flow of controls based on the ActionForward object that is returned.


Regards,<br />Roshani
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Roshani,

Thanks for your valuable inputs. Could you explain me where to implement the business logic modules? Since as per the standardsm, the Action class is not the correct place to implement the business logic.

regards,
dinesh.
Ashkrit Sharma
Greenhorn

Joined: Oct 05, 2006
Posts: 7
You can use POJO to write Business Logic or java have EJB's for same.
You should develope your business logic as component,so that it can be re-used
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Ashkrit,

Thank you. I will try and come back if i have any more issues.
Thanks again.

regards,
dinesh.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi
The controller is nothing but the ActionServlet (org.apache.struts.action.ActionServlet) which redirects and regulates the flow. If required you can override it. It is configured in web.xml as follows.

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
.....
....
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
<servlet-mapping>

Whenever a request which comes with a *.do at the end (ex. http://localhost:8080/myStrutsApp/login.do) the container invokes the Struts ActionController as per the configuration.

does that clarify your main doubt?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Rhagavan,

Yes, it clarified my main doubt. Thanks! So I can write my own Servlet to replace the default action servlet. Am i correct?

regards,
dinesh.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi Dinesh,

Rhagavan - different way you pronounced my name


Yes, it clarified my main doubt. Thanks! So I can write my own Servlet to replace the default action servlet. Am i correct?


You can very well override the default ActionServlet. Though there are few necessary steps to be followed to override, i would suggest you to proceed with the default ActionServlet itself till you get a good understanding on its flow.

HtH.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Raghavan,

Sorry for addressing you Rhagavan. Yes, I too decided to go with the default ActionServlet till I get familiar with the framework.

Soon i will need help in my progress.

Thanks again,
regards,
dinesh.
raj
Greenhorn

Joined: Feb 09, 2007
Posts: 8
Originally posted by RoshaniG Gopal:
Hi dinesh

The FormClass(RegisterForm.java) is a java bean(POJO). Controller is framework(along with struts-config) which calls the ActionClass(RegisterAction.java).
Actionclass- may/maynot have the business logic in it. As per stds and best practices it should not contain any business logic. It should just act as a place where you direct the flow of controls based on the ActionForward object that is returned.


in struts framework, we are using struts-config.xml file, actionservlet uses some parser to parse this xml file. which parser using by struts framework?
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi Dinesh,

Thats okay.

go ahead.. you are most welcome for any further queries..

Good luck.
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Hi rajeshmanepalli ,


in struts framework, we are using struts-config.xml file, actionservlet uses some parser to parse this xml file. which parser using by struts framework?


You can probably look into the Source Code of Struts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help to understand the ActionServlet