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.