GeeCON Prague 2014*
The moose likes Struts and the fly likes Cannot find ActionMappings or ActionFormBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot find ActionMappings or ActionFormBeans" Watch "Cannot find ActionMappings or ActionFormBeans" New topic
Author

Cannot find ActionMappings or ActionFormBeans

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

I am having a lot of trouble trying out this first struts example. I am very new to struts. I am running this example with struts 1.2.2 and tomcat 5.0.28 and i am getting the Exception in the heading. Please tell me where i have gone wrong. Been doing this for hours now ! I looked at other posts where people complained that this error was being thrown but it didnt help me much.

--------------------------------------------
indexForm.java
--------------------------------------------

package com.login;

import org.apache.struts.action.*;

public class indexForm extends ActionForm
{
private String password;

public String getPassword()
{
return password;
}
public void setPassword( String pass )
{
password = pass;
}
}




----------------------------------------------------
indexAction.java
----------------------------------------------------

package com.login;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
import com.business.*;

public class indexAction extends Action
{
public ActionForward perform ( ActionMapping map,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response
)
{
indexForm index=null;
if ( form instanceof indexForm )
{
index = (indexForm) form;
}
else
{
System.out.println("Nulled argument");
return map.findForward("failure");
}

String password = index.getPassword();
if ( new loginLogic().validate(password) )
{
return map.findForward("success");
}
return map.findForward("failure");
}

}

-------------------------------------
loginLogic.java
-------------------------------------

package com.business;

public class loginLogic
{
public boolean validate( String password )
{
if( password != null && password.equals("hello"))
{
return true;
}
return false;
}
}


------------------------------------------------
struts-config.xml
------------------------------------------------


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<struts-config>
<form-beans>
<form-bean name="indexform" type="com.login.indexForm"/>
</form-beans>

<action-mappings>
<actionname="indexform"
type="com.login.indexAction"
path="/index">
<forward name="success" path="/success.html">
<forward name="failure" path="/failure.html">
</action-mappings>
</struts-config>



----------------------------------------------------
web.xml
----------------------------------------------------


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//
DTD Web Application 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>index</servlet-name>
<servlet-class>com.login.indexAction</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>


------------------------------------------------------
index.jsp
------------------------------------------------------

<%@ taglib uri="./WEB-INF/lib/struts-html.tld" prefix="html" %>
<%@ taglib uri="./WEB-INF/lib/struts-bean.tld" prefix="bean" %>
<html:html>
<html:form action="/index" method="post">
<html assword property="password" size="10"/>
<html:submit/>
</html:form>

</html:html>









Please help. Have i missed a tag or a .do somewhere ?

Thank you.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Exactly what exception are you getting?

- Brent
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
Hi,

Try overriding the execute() method in the Action class instead of the perform() method. It takes the same arguments and returns an ActionForward. This might be because using struts 1.2.X.




Also please follow naming conventions for Java Classes. Java classe names should start with capital case.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The main problem is that your web.xml file is incorrect. IndexAction is not a servlet and should not be declared in web.xml. Your web.xml file should look like this:


A Struts application typically has only one servlet, and that is the Struts ActionServlet. The subclasses of the Action class that you write are declared in the struts-config.xml file, but not in web.xml.


Merrill
Consultant, Sima Solutions
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Thanks everyone ! I got it to work. Here are the changes i made.

* Changed the web.xml like i was asked to.

* Did an override of the execute method since control was not transfered to
my action if i used the perform method.

* Changed the dtd url to the correct version. If the correct version is not
given the web container will not be able to understand your tags properly
and will throw an error saying for example "action" tag must be defined
before use : "forward" tag must be defined before use.

Finally ! It works !

Thanks again
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Cool! Mind if I join you...

- Brent
 
Don't get me started about those stupid light bulbs.
 
subject: Cannot find ActionMappings or ActionFormBeans