• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help to understand the ActionServlet

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashkrit,

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

regards,
dinesh.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dinesh,

Thats okay.

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

Good luck.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic