*
The moose likes Struts and the fly likes NullPointerException, can not able to access  ActionForm data inside execute() metod of Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "NullPointerException, can not able to access  ActionForm data inside execute() metod of Action class" Watch "NullPointerException, can not able to access  ActionForm data inside execute() metod of Action class" New topic
Author

NullPointerException, can not able to access ActionForm data inside execute() metod of Action class

Hemakanta Sethi
Greenhorn

Joined: Jul 19, 2011
Posts: 17

Hi.. Friends
I am trying to solve the below Exception, but i could not.

javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)


Below i give the all the related files with directory structure.
StrutsApp1
|---------->WEB-INF
| |---------->web.xml
| |---------->struts-config.xml
| |---------->lib(it contain related jar files)
| |---------->classes
| |---------->LoginAction.java
| |---------->LoginForm.java
|------------>login.jsp
|------------>success.jsp
|------------>failure.jsp


Can anyone please guide me on how to resolve this issue.
Below are the details of the Exception.

Exception Details
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.lang.NullPointerException
LoginAction.execute(LoginAction.java:18)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.


web.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>


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

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="frm1" type="LoginForm" />
</form-beans>
<action-mappings>
<action path="/login" name="frm1" type="LoginAction" >
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
</action-mappings>
</struts-config>


login.jsp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html>
<body>
<center>
<html:form action="login.do">
<h2>UserName:<html:text property="uname"/></h2>
<h2>Password:<html:password property="pwd"/></h2>
<html:submit value="Click"/>
</html:form>
</center>
</body>
</html>


LoginForm.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// LoginForm.java

import org.apache.struts.action.*;
public class LoginForm extends ActionForm
{
private String uname, pwd;

public void SetUname(String uname){
this.uname = uname;
}
public String getUname(){
return uname;
}

public void SetPwd(String pwd){
this.pwd = pwd;
}
public String getPwd(){
return pwd;
}
}


LoginActio.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// LgonAction.java
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class LoginAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{

LoginForm lf = (LoginForm)form;

String usrname = lf.getUname();
String passwrd = lf.getPwd();

System.out.println(usrname);
System.out.println(passwrd);

ActionForward af = null;
if(usrname.equals("satya") && passwrd.equals("struts"))
{
af = mapping.findForward("success");
}
else
{
af = mapping.findForward("failure");
}
return af;
} //execute
} // LoginForm


failure.jsp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<%
out.println("<h2>Login failed</h2>");
%>

success.jsp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<%
out.println("<h2>Login Success</h2>");
%>


I rechecked the xml mapping file many times still i could not able to find out the error. Can anyone please guide me on how to resolve this issue?

Advanced Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException, can not able to access ActionForm data inside execute() metod of Action class
 
Similar Threads
tomcat cannot display jsp struts
Problem running a simple webapplication in struts
how will arrange in the action mapping in the strut-config.xml?
error with implementing a basic struts example
Problem with login page