JSP Coercion Error

Hello. I am developing an app for my employer, and I am encountering an error due to coercion somewhere in one of my pages. I am having trouble locating it. I hope someone can provide me with a bit of assistance.

exception
 
javax.servlet.ServletException: Attempt to coerce a boolean value "false" to type "java.lang.Long"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.jsp.process_jsp._jspService(process_jsp.java:2207)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
root cause
 
javax.servlet.jsp.el.ELException: Attempt to coerce a boolean value "false" to type "java.lang.Long"
      org.apache.commons.el.Logger.logError(Logger.java:481)
      org.apache.commons.el.Logger.logError(Logger.java:498)
      org.apache.commons.el.Logger.logError(Logger.java:566)
      org.apache.commons.el.Coercions.coerceToPrimitiveNumber(Coercions.java:422)
      org.apache.commons.el.Coercions.applyArithmeticOperator(Coercions.java:872)
      org.apache.commons.el.ArithmeticOperator.apply(ArithmeticOperator.java:83)
      org.apache.commons.el.BinaryOperatorExpression.evaluate(BinaryOperatorExpression.java:170)
      org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
      org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
      org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:899)
      org.apache.jsp.jsp.process_jsp._jspx_meth_c_if_97(process_jsp.java:20735)
      org.apache.jsp.jsp.process_jsp._jspService(process_jsp.java:2100)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.



The code which causes it is:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%!String firstname;
 
      String lastname;
 
      %>
 
 
<%-- Check for valid session --%>
<c:if test="${validUser == null}">
      <jsp:forward page="../login.jsp">
            <jsp:param name="error" value="4" />
      </jsp:forward>
</c:if>
 
<%-- ****************Address Stuff  *********** --%>
 
<%-- Check if address/location exists --%>
 
<sql:query var="add_exists">
      SELECT
            *
      FROM
            address_table
      WHERE
            (address_1 = ?)
            
      <sql:param value="${param.add_1}" />
</sql:query>
 
<%-- if a record is returned, get the address id --%>
 
<c:if test="${add_exists.rowCount == 1}">
      <c:forEach items="${add_exists.rows}" var="add_row">
            <c:set var="add_id" value="${add_row.add_id}" />
      </c:forEach>
</c:if>
 
 
<%-- If 1 record is not returned from query, add the address--%>
<c:if test="${add_exists.rowCount != 1}">
      <sql:update var="insert_address">INSERT INTO address_table VALUES ( 0, ?, ?, ?, ?, ?, ?, ?, ? )
                  
            <sql:param value="${param.Company}" />
            <sql:param value="${param.Store_num}" />
            <sql:param value="${param.add_1}" />
            <sql:param value="${param.add_2}" />
            <sql:param value="${param.city}" />
            <sql:param value="${param.province}" />
            <sql:param value="${param.country}" />
            <sql:param value="${param.phone}" />
      </sql:update>
 
      <%--now get the address id.... --%>
 
      <sql:query var="add_exists">
                  SELECT
                        add_id
                  FROM
                        address_table
                  WHERE
                        (address_1 = ?)
            
            <sql:param value="${param.add_1}" />
      </sql:query>
 
      <c:forEach items="${add_exists.rows}" var="row">
            <c:set var="add_id" value="${row.add_id}" />
      </c:forEach>
</c:if>
 
 
<%-- ************  check if crew member1 exists, and get id# ****************--%>
<c:if test="${not empty param.Crew1_name}">
      <c:out value="testing to see if c1 exists " />
 
      <sql:query var="crew1_exists">
                        SELECT
                              *
                        FROM
                              crew_map
                        WHERE
                              (last_name = ?) AND (first_name = ?)
                      
            <sql:param
                  value='<%= com.acps.takedown.NameParserBean.parseLastname(request
                                    .getParameter("Crew1_name")) %>' />
            <sql:param
                  value='<%= com.acps.takedown.NameParserBean.parseFirstname(request
                        .getParameter("Crew1_name")) %>' />
      </sql:query>
 
      <c:if test="${crew1_exists.rowCount == 1}">
            <c:forEach items="${crew1_exists.rows}" var="crew1_row">
                  <c:set var="c1id" value="${crew1_row.person_id}" />
            </c:forEach>
      </c:if>
 
 
      <%-- if not, add him --%>
 
      <c:if test="${crew1_exists.rowCount != 1}">
            <c:out value="c1 does not exist, adding him" />
            <sql:update var="add_crew1">
                              INSERT INTO crew_map VALUES
                              (0, ?, ? )
            
                  <sql:param
                        value='<%= com.acps.takedown.NameParserBean.parseLastname(request
                                    .getParameter("Crew1_name")) %>' />
                  <sql:param
                        value='<%= com.acps.takedown.NameParserBean.parseFirstname(request
                        .getParameter("Crew1_name")) %>' />
            </sql:update>
 
            <%-- and then get the id --%>
            <sql:query var="crew1_get_id">
                        SELECT
                              *
                        FROM
                              crew_map
                        WHERE
                              (last_name = ?) AND (first_name = ?)
                      <sql:param
                        value='<%= com.acps.takedown.NameParserBean.parseLastname(request
                                    .getParameter("Crew1_name")) %>' />
                  <sql:param
                        value='<%= com.acps.takedown.NameParserBean.parseFirstname(request
                        .getParameter("Crew1_name")) %>' />
            </sql:query>
            <c:forEach items="${crew1_get_id.rows}" var="crew1_row">
                  <c:set var="c1id" value="${crew1_row.person_id}" />
            </c:forEach>
      </c:if>
</c:if>
 
 
<sql:update var="insert_job">INSERT INTO job_table VALUES ( 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?  )
                  
      <sql:param value="${param.Date}" />
      <sql:param value="${add_id}" />
      <sql:param value="${c1id}" />
      <sql:param value="${c2id}" />
      <sql:param value="${c3id}" />
      <sql:param value="${c4id}" />
      <sql:param value="${c5id}" />
      <sql:param value="${c6id}" />
      <sql:param value="${param.travel_time}" />
      <sql:param value="${param.start_time}" />
      <sql:param value="${param.end_time}" />
      <sql:param value="${param.delay_time}" />
      <sql:param value="${param.Comments}" />
</sql:update>
 
<sql:query var="job_id_check">
      SELECT max(job_id) AS max_job_id FROM job_table
</sql:query>
 
<c:forEach items="${job_id_check.rows}" var="job_row">
      <c:set var="job_id" value="${job_row.max_job_id}" />
</c:forEach>



Thank you for any and all help/suggestions/ideas. It is really appreciated!
LVL 3
CaydelAsked:
Who is Participating?
 
bloodredsunConnect With a Mentor Commented:
It might be because you have nested <c:if> statements

<c:if test="${not empty param.Crew1_name}">
...
     <c:if test="${crew1_exists.rowCount == 1}">
          <c:forEach items="${crew1_exists.rows}" var="crew1_row">
               <c:set var="c1id" value="${crew1_row.person_id}" />
          </c:forEach>
     </c:if>
...
</c:if>

Your jsp design would really benefit from having a backing action or servlet to do all this logic in rather than having in all in your presentation jsp. If this is not the root cause then I suggest that you fall back on the fairly basic tactic of commentating out large portions of your code until you find the relevent section.

To find out what exactly it is, you should look at the process_jsp.java file on line 2207. This can be found in <tomcat home>\work\Catalina\localhost\<your appname>\\org\apache\jsp

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.