• 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

Cannot find ActionMappings or ActionFormBeans

 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly what exception are you getting?

- Brent
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool! Mind if I join you...

- Brent
 
reply
    Bookmark Topic Watch Topic
  • New Topic