Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 17
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic