10:33 am - Wednesday November 21, 2018

Struts java. lang. NullPointerException MyController. execute (MyController. java: 15)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

HTTP Status 500 –


type Exception report

message

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

exception


javax.servlet.ServletException

org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)

org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)

javax.servlet.http.HttpServlet.service(HttpServlet.java:627)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.NullPointerException

MyController.execute(MyController.java:15)

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)

org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)

javax.servlet.http.HttpServlet.service(HttpServlet.java:627)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.33 logs.

Coding:

Error: 

<struts-config>

	<form-beans>
		<form-bean type="MyModell" name="model" />
	</form-beans>

	<action-mappings>
		<action path="/myActionForm" type="MyController" name="model"
			input="/first.jsp">

			<forward name="xxx" path="/pass.jsp" />
			<forward name="error" path="/fail.jsp" />
		</action>
	</action-mappings>

</struts-config>

Model class:

MyModel.java


import org.apache.struts.action.ActionForm;

public class MyModel extends ActionForm {
	private String name;

	public void setName(String n) {
		name = n;
	}

	public String getName() {
		return name;
	}
}

Correction:

<struts-config>

	<form-beans>
		<form-bean type="MyModel" name="model" />
	</form-beans>

	<action-mappings>
		<action path="/myActionForm" type="MyController" name="model"
			input="/first.jsp">

			<forward name="xxx" path="/pass.jsp" />
			<forward name="error" path="/fail.jsp" />
		</action>
	</action-mappings>

</struts-config>

Description:

This exception occurs when there is a mismatch in loading model class in struts config.xml check mapping in bean type property name and model class name

Filed in: Z-AStruts Codes

Comments are closed.