Showing posts with label struts. Show all posts
Showing posts with label struts. Show all posts

Error Cannot find ActionMappings or ActionFormBeans collection , Cannot retrieve mapping for action in Struts 1.2.

Cannot find ActionMappings or ActionFormBeans collection  , when he access the login.jsp of  the application deployed in WebSphere Application Server (WAS)  running on the Linux server. The application was developed using the framework  struts 1.2 and the application works fine with ide WSAD. The above error is thrown when the application server executes the  following line

<html:form name="loginForm" type="Sales.login.LoginForm" method="post" scope="request" action="/login.do" onsubmit="return submitForm()" >
 

The above error may occur due to various reasons.

Some of the situations  where the error may be thrown are as follows

Situation 1 :  When the Request Processor  searches for  the mapping of  this request, if  it is not able to  find the mappings that  are defined in the struts-config.xml , the following errors may be thrown depending upon the situation.

a)  If  the server is able to load the struts-config.xml , but the   mapping  is not available in the struts-config.xml . for eg.  if  the JSP has  <html:form action="/login" method="post" type="LoginAction">
                         then your struts-config.xml should have mapping for action parameter i.e. "/login"  something like

<action-mappings>
    <action path="/login"        type="LoginAction"    name="loginForm"          scope="request"       validate="false"   input="/login.jsp" >
     </action>
</action-mappings>


But if the mapping is not present in the   struts-config.xml , then you may get the error    [Cannot retrieve mapping for action /login1]: javax.servlet.jsp.JspException: Cannot retrieve mapping for action /login

b) But the above mapping is present in the struts-config.xml  , but you are getting the error  Cannot find ActionMappings or ActionFormBeans collection   ,  That means the sever is not able to load the struts-config.xml fle.

 To solve , the above problem ,  Please ensure , the path & file name of struts-config.xml file mentioned in the web.xml file  is correct and case sensitive.

  In our  case , the problem was very silly and the problem got solved when i  add a slash (/) infront of WEB-INF ...

The belows lines are part of the web.xml and the param-value  to be passed to  ActionServlet is wrongly mentioned

<servlet>
   <servlet-name>action</servlet-name>
   <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
   <init-param>
    <param-name>config</param-name>
    <param-value>WEB-INF/struts-config.xml</param-value>   OR   <param-value>/web-inf/struts-config.xml</param-value>    // Wrong
   </init-param>
 

In the above lines  , changing  the line   <param-value>WEB-INF/struts-config.xml</param-value> OR  <param-value>web-inf/struts-config.xml</param-value>  to

<param-value>/WEB-INF/struts-config.xml</param-value>  , will solve the problem


Situation 2 :   If   the sever is able to load the struts-config.xml fle and also the  mapping is present in the struts-config.xml , then the Request Processor does  process  any ActionForm bean related to this request. (i.e. finding , loading  the ActionFormBeans collection, ..etc ) .

             Various classes such as org.apache.struts.action.ActionFormBeans ,  org.apache.commons.collections.FastHashMap   are involved for the above process.  And the following jars are  involved
                  struts.ear
                  commons-collections.jar
                   commons-beanutils.jar

  ....
  .....
            So  If you miss the jar files such as    commons-collections.jar  , commons-beanutils.jar in the class path , then the request processor may not find the ActionFormBeans collection , and the error Cannot find ActionMappings or ActionFormBeans collection  is thrown

explain JSF framework compare with the Struts framework

Struts framework  versus JavaServer Faces

  • Matured since Struts has been around for a few years.
It has got several successful implementations.
JSF is in its early access release and as a result somewhat
immature.

  • The heart of Struts framework is the Controller, which
uses the Front Controller design pattern and the
Command design pattern. Struts framework has got
only single event handler for the HTTP request.
The heart of JSF framework is the Page Controller Pattern where
there is a front controller servlet where all the faces request go
through with the UI components and then fire off events for each
component and render the components using a render toolkit. So
JSF can have several event handlers on a page. Also JSF
loosely couples your model, where it can hook into your model (i.e
unlike Struts your model does not have to extend JSF classes).

  • Struts does not have the vision of Rapid Application
Development (RAD).
JSF was built with a component model in mind to allow RAD. JSF
can be thought of as a combination of Struts framework for thin
clients and the Java Swing user interface framework for thick
clients.
Has got flexible page navigation using navigation rules
inside the struts-config.xml file and Action classes
using maoping.findForward(…) .
JSF allows for more flexible navigation and a better design
because the navigation rule (specified in faces-config.xml ) is
decoupled from the Action whereas Struts forces you to hook
navigation into your Action classes.
  • Struts is a sturdy frame work which is extensible and
flexible. The existing Struts applications can be
migrated to use JSF component tags instead of the
original Struts HTML tags because Struts tags are
superseded and also not undergoing any active
development. You can also use the Struts-Faces
Integration library to migrate your pages one page at
a time to using JSF component tags.
JSF is more flexible than Struts because it was able to learn from
Struts and also extensible and can integrate with RAD tools etc.
So JSF will be a good choice for new applications.?