• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why error "Attempted a bean operation on a null object."???  RSS feed

 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting an error:
org.apache.jasper.JasperException: Attempted a bean operation on a null object.
but not sure why???
Here is the first JSP which I have simply called form.jsp
Then it calls another form called processForm.jsp
Please note both of the form.jsp and processForm.jsp are in the same directory.

<!-- This is form.jsp -->
<html>
<head>
<title> Welcome </title>
</head>
<body>

<h1> Welcome to the ABC Corporation Web site.
<form action="processform.jsp" method="get">
<br>
Enter your name:
<input type="text" name="userName"><br>
Where do you live?
<input type="text" name="region"><br>
<input type="submit" name="Submit info">
</form>
</body>
</html>
<!-- This is processForm.jsp -->
<html>
<head>
<jsp:useBean id="processFormBeanId" scope="session" class="mybeans.processFormBean" />
<jsp:setProperty name="processFormBeanId" property="*" />
<title> Welcome </title>
</head>
<body>

<h1> Welcome,
<jsp:getProperty name="processFromBeanId" property="userName" />
<h1>
<br> You selected the following location: <br>
<jsp:getProperty name= "processFromBeanId" property="location" />
</body>
</html>
The processform.jsp uses a bean which I have appropriately called
"processFormBeanId.java"
/* class processFormBean.java */
package mybeans;
public class processFormBean
{
private String userName;
private String location;
public void setUserName(String newValue)
{
userName = newValue;
}
public void setLocation(String locationValue)
{
location = locationValue;
}
private String getUserName()
{
return userName;
}

public String getLocation()
{
return location;
}
}
can any one help me?
Here is the full error message:
Error: 500
Location: /myJSPs/jsp/Whitehead/chap6/processform.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Attempted a bean operation on a null object.
at org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:420)
at jsp.Whitehead.chap6.processform_1._jspService(processform_1.java:88)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
 
Ant Swa
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First check your code for possible errors before trying it in the server.
I found two by just looking at it and there can be more. (if i am not mistaken)
1. you have assigned the bean id as processFormBeanId and u are reffering processFromBeanId. ( There is a difference between processFromBeanId and processFormBeanId )

2. All your get set methods should be public.
( private String getUserName() )

!SunCertified
 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx,
 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that in form.jsp, the form action is directed at processform.jsp. The name of the file is processForm.jsp. As a matter of style it is incorrect, but does case matter here?
 
Ant Swa
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it will depend on your web server. ( it is nothing to do with jsp) some web servers does not check the case sensitivity of the url and some may. I ran the corrected sample in Weblogic and it works when the form action unchanged.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!