You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kenneth Litwak <ja...@yahoo.com> on 2001/08/16 00:35:11 UTC

Newbie help needed: error running JSP

   I just ran my first JSP that uses a form and got an
error. Unfortunately, the stack trace doesn't tell me
where in the JSP the error occured (that I can tell)
or where in my helper bean the problem ight be.  I'd
heard that JSPs are hard to debug, and now I see why. 
The JSP engine is not very helpful with what's wrong. 
Here's the stack trace, followed by the JSP code.

Location: /examples/jsp/form/Form.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:424)
        at
jsp.f_00025rm._0002fjsp_0002fform_0002fForm_0002ejspForm_jsp_0._jspService(_0002fjsp_0002fform_0002fForm_0002ejspForm_jsp_0.java:122)
        at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
        at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
        at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at
org.apache.tomcat.core.Handler.service(Handler.java:286)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

JSP code:
<html>
<body bgcolor="#c8d8f8">
<form action="/examples/jsp/form/Form.jsp"
method=post>
<center>
<table cellpadding=4 cellspacing=2 border=0>

<th bgcolor="#CCCCFF" colspan=2>
<font size=5>User Registration</font>
</th>

<tr>
<td valign=top> 
<b>First Name</b> 
<br>
<input type="text" name="firstName" size=15></td>
<td  valign=top>
<b>Last Name</b>
<br>
<input type="text" name="lastName" size=15></td>
</tr>

<tr>
<td valign=top colspan=2>
<b>E-Mail</b> 
<br>
<input type="text" name="email" size=20>
<br></td>
</tr>

<tr>
<td  valign=top colspan=2>
<b>What languages do you program in?</b>
<br>
<input type="checkbox" name="languages"
value="Java">Java&nbsp;&nbsp; 
<input type="checkbox" name="languages"
value="C++">C++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="languages"
value="C">C<br>
<input type="checkbox" name="languages"
value="Perl">Perl&nbsp;&nbsp;
<input type="checkbox" name="languages"
value="COBOL">COBOL
<input type="checkbox" name="languages"
value="VB">VB<br>
</td>
</tr>

<tr>
<td  valign=top colspan=2>
<b>How often can we notify you regarding your
interests?</b>
<br>
<input type="radio" name="notify" value="Weekly"
checked>Weekly&nbsp;&nbsp;
<input type="radio" name="notify"
value="Monthly">Monthly&nbsp;&nbsp; 
<input type="radio" name="notify"
value="Quarterly">Quarterly 
<br></td>
</tr>

<tr>
<td  align=center colspan=2>
<input type="submit" value="Submit"> <input
type="reset"  value="Reset">
</td>
</tr>

</table>
</center>
</form>
<%-- Create the bean only when the form is posted --%>
<%
if (request.getMethod().equals("POST"))
     {
%>
<jsp:useBean id="formHandler"
class="com.shopping.FormBean">
<%-- provide a setProperty tag and ensure that the
setter methods are invoked via introspection 
--%>
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<p>
<hr>
<font color=red>
<b>You submitted:<P>
First Name:</b><br>
<%-- invoke the getter method to display the firstName
using the getProperty tag --%>
<jsp:getProperty name="formHandler"
property="firstName"/><br>
<br><b>Last Name:</b><br>
<%-- invoke the getter method to display the lastName
using the getProperty tag --%>
<jsp:getProperty name="formhandler"
property="lastName"/><br>
<br><b>Email:</b><br>
<%-- invoke the getter method to display the email
address using the getProperty tag 
<jsp:getProperty name="formHandler"
property="email"/><br>
--%>
<b>Languages:</b><br>
<%
   String[] lang = formHandler.getLanguages();
   if (!lang[0].equals("1")) 
       {
        out.println("<ul>");
        for (int i=0; i<lang.length; i++)
            out.println("<li>"+lang[i]);
        out.println("</ul>");
       }
   else out.println("Nothing was selected<br>");
%>
<b>Notification:</b><br>
<%-- invoke the getter method to display the
notification status using the getProperty tag 
--%>
<jsp:getProperty name="formHandler"
property="notify"/><br>
<br>
<%
}
%>
</font>
</body>
</html>

I think this would be better as an attachment but lots
of mailing lists don't like those, so ugly or not,
there it is.  Thanks.

Ken

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

RE: Newbie help needed: error running JSP

Posted by "Rob S." <rs...@home.com>.
Well, of course the stack will be container-specific =)  In WebLogic, the
exception will be something like com.weblogic.blah.foo with a different
message.  The exception message there seemed descriptive enough to debug.

- r

> -----Original Message-----
> From: Kenneth Litwak [mailto:javajedi2@yahoo.com]
> Sent: Wednesday, August 15, 2001 7:09 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: Newbie help needed: error running JSP
>
>
> Rob S. wrote:
> ot to be a jerk or anything, your "newbie help"
> questions are fine and all,
> but the problem is that the only connection they
> have to Tomcat is that
> you're using the container.
>
> It's like if I emailed the GCC or Visual Studio
> lists saying, "how come I'm
> getting all of these memory leaks in my
> programs?"  See what I'm saying?
> You really should pick up a book on JSPs /
> Servlets...
>
>    Rob, I understand your point.  The reason I posted
> here is that the stack trace appears to me completley
> unique to Tomcat. Weblogic might produce totally
> different information, as might Websphere as might the
> J2EE RI.  I don't know what from the stack trace is
> unique to Tomcat, and therefore a config error I've
> made, and what is common to all JSP engines.  How do
> you know the diference?  Thanks.
>
> Ken
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
>


RE: Newbie help needed: error running JSP

Posted by Kenneth Litwak <ja...@yahoo.com>.
Rob S. wrote:
ot to be a jerk or anything, your "newbie help" 
questions are fine and all,
but the problem is that the only connection they 
have to Tomcat is that
you're using the container.

It's like if I emailed the GCC or Visual Studio 
lists saying, "how come I'm
getting all of these memory leaks in my 
programs?"  See what I'm saying?
You really should pick up a book on JSPs / 
Servlets...

   Rob, I understand your point.  The reason I posted
here is that the stack trace appears to me completley
unique to Tomcat. Weblogic might produce totally
different information, as might Websphere as might the
J2EE RI.  I don't know what from the stack trace is
unique to Tomcat, and therefore a config error I've
made, and what is common to all JSP engines.  How do
you know the diference?  Thanks.

Ken

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

RE: Newbie help needed: error running JSP

Posted by "Rob S." <rs...@home.com>.
Hiya Ken,

Not to be a jerk or anything, your "newbie help" questions are fine and all,
but the problem is that the only connection they have to Tomcat is that
you're using the container.

It's like if I emailed the GCC or Visual Studio lists saying, "how come I'm
getting all of these memory leaks in my programs?"  See what I'm saying?
You really should pick up a book on JSPs / Servlets...

- r

> -----Original Message-----
> From: Kenneth Litwak [mailto:javajedi2@yahoo.com]
> Sent: Wednesday, August 15, 2001 6:35 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Newbie help needed: error running JSP
>
>
>    I just ran my first JSP that uses a form and got an
> error. Unfortunately, the stack trace doesn't tell me
> where in the JSP the error occured (that I can tell)
> or where in my helper bean the problem ight be.  I'd
> heard that JSPs are hard to debug, and now I see why.
> The JSP engine is not very helpful with what's wrong.
> Here's the stack trace, followed by the JSP code.
>
> Location: /examples/jsp/form/Form.jsp
>
> Internal Servlet Error:
>
> org.apache.jasper.JasperException: Attempted a bean
> operation on a null object.
>         at
> org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspR
> untimeLibrary.java:424)
>         at
> jsp.f_00025rm._0002fjsp_0002fform_0002fForm_0002ejspForm_jsp_0._js
> pService(_0002fjsp_0002fform_0002fForm_0002ejspForm_jsp_0.java:122)
>         at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
>         at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Jsp
> Servlet.java:177)
>         at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
>         at
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
>         at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
>         at
> org.apache.tomcat.core.Handler.service(Handler.java:286)
>         at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>         at
> org.apache.tomcat.core.ContextManager.internalService(ContextManag
> er.java:797)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>         at
> org.apache.tomcat.service.http.HttpConnectionHandler.processConnec
> tion(HttpConnectionHandler.java:210)
>         at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
>         at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
>         at java.lang.Thread.run(Thread.java:484)
>
> JSP code:
> <html>
> <body bgcolor="#c8d8f8">
> <form action="/examples/jsp/form/Form.jsp"
> method=post>
> <center>
> <table cellpadding=4 cellspacing=2 border=0>
>
> <th bgcolor="#CCCCFF" colspan=2>
> <font size=5>User Registration</font>
> </th>
>
> <tr>
> <td valign=top>
> <b>First Name</b>
> <br>
> <input type="text" name="firstName" size=15></td>
> <td  valign=top>
> <b>Last Name</b>
> <br>
> <input type="text" name="lastName" size=15></td>
> </tr>
>
> <tr>
> <td valign=top colspan=2>
> <b>E-Mail</b>
> <br>
> <input type="text" name="email" size=20>
> <br></td>
> </tr>
>
> <tr>
> <td  valign=top colspan=2>
> <b>What languages do you program in?</b>
> <br>
> <input type="checkbox" name="languages"
> value="Java">Java&nbsp;&nbsp;
> <input type="checkbox" name="languages"
> value="C++">C++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> <input type="checkbox" name="languages"
> value="C">C<br>
> <input type="checkbox" name="languages"
> value="Perl">Perl&nbsp;&nbsp;
> <input type="checkbox" name="languages"
> value="COBOL">COBOL
> <input type="checkbox" name="languages"
> value="VB">VB<br>
> </td>
> </tr>
>
> <tr>
> <td  valign=top colspan=2>
> <b>How often can we notify you regarding your
> interests?</b>
> <br>
> <input type="radio" name="notify" value="Weekly"
> checked>Weekly&nbsp;&nbsp;
> <input type="radio" name="notify"
> value="Monthly">Monthly&nbsp;&nbsp;
> <input type="radio" name="notify"
> value="Quarterly">Quarterly
> <br></td>
> </tr>
>
> <tr>
> <td  align=center colspan=2>
> <input type="submit" value="Submit"> <input
> type="reset"  value="Reset">
> </td>
> </tr>
>
> </table>
> </center>
> </form>
> <%-- Create the bean only when the form is posted --%>
> <%
> if (request.getMethod().equals("POST"))
>      {
> %>
> <jsp:useBean id="formHandler"
> class="com.shopping.FormBean">
> <%-- provide a setProperty tag and ensure that the
> setter methods are invoked via introspection
> --%>
> <jsp:setProperty name="formHandler" property="*"/>
> </jsp:useBean>
> <p>
> <hr>
> <font color=red>
> <b>You submitted:<P>
> First Name:</b><br>
> <%-- invoke the getter method to display the firstName
> using the getProperty tag --%>
> <jsp:getProperty name="formHandler"
> property="firstName"/><br>
> <br><b>Last Name:</b><br>
> <%-- invoke the getter method to display the lastName
> using the getProperty tag --%>
> <jsp:getProperty name="formhandler"
> property="lastName"/><br>
> <br><b>Email:</b><br>
> <%-- invoke the getter method to display the email
> address using the getProperty tag
> <jsp:getProperty name="formHandler"
> property="email"/><br>
> --%>
> <b>Languages:</b><br>
> <%
>    String[] lang = formHandler.getLanguages();
>    if (!lang[0].equals("1"))
>        {
>         out.println("<ul>");
>         for (int i=0; i<lang.length; i++)
>             out.println("<li>"+lang[i]);
>         out.println("</ul>");
>        }
>    else out.println("Nothing was selected<br>");
> %>
> <b>Notification:</b><br>
> <%-- invoke the getter method to display the
> notification status using the getProperty tag
> --%>
> <jsp:getProperty name="formHandler"
> property="notify"/><br>
> <br>
> <%
> }
> %>
> </font>
> </body>
> </html>
>
> I think this would be better as an attachment but lots
> of mailing lists don't like those, so ugly or not,
> there it is.  Thanks.
>
> Ken
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
>