I am new to struts and I have a query on it. We have Interceptors, Actions classes and view classes in struts applications right. And we make sure that the URL is tied to an action class and an action class is tied to a jsp view page [ of course depends on the output it returns ].
Now, if I have a jsp/html file and I have a form, then I should be mentioning the action class that is going to take up the form processing right? Something like,
Now, we are now configuring the action class in the html/jsp itself instead of the usual struts.xml configuration file. [I am on struts2 by the way.] Is this in any way a bad design..or a violation of MVC? Since view is tied to the action class.
Like I mentioned, I am very new to struts...so please let me know if I did miss anything.
we are now configuring the action class in the html/jsp itself instead of the usual struts.xml configuration file
If by this , you mean to say that you are writing java code inside the JSPs , then yes, it is considered a bad MVC design . Its preferred to write your code in separate action classes. The JSPs should only be used for view purposes with some jsp scriptlets. But putting in whole java code inside the jsp is bad practice.
Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Pavan Kumar Dittakavi wrote: Now, if I have a jsp/html file and I have a form, then I should be mentioning the action class that is going to take up the form processing right? Something like,
If I understand what you are saying, what you put in the action parameter of the form tag is the name of the action as configured in struts.xml. The name of the action in struts.xml can certainly be the same as the action class name. This may or may not be good design. It depends on other choices you make.
For example, I tend to put CRUD methods for a particular data element in the same action. This means I will have several actions in struts.xml that point to the same class like so:
So the forms that create and edit X data will refer to the name (createX) and not the action class(XAction).
Thank you so much guys. Joe, your explanation clarified my doubt. I thought that the "action" attribute refers to the concrete class itself and so I wondered if that was a good programming practice. But since it can point to the action name, we should be fine even if the underlying class name changes [ for instance..eventhough it might not be likely].
Thanks for your time
subject: Query on struts congfiguration in a 'form'