Solved

Why do I get "Document root element is missing..." error message?

Posted on 2003-11-21
11
2,685 Views
Last Modified: 2013-11-19
I have a fairly simple JSP program that works flawlessly when the user is patient and waits for the query to complete before clicking on 'NEXT PAGE', 'PREVIOUS PAGE', or, on the 'UPDATE' buttons. However, if the user is not patient and keeps on clicking the buttons before the underlying query is completed, it will fail with the following error message:
    --------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Error on line 1 of document  : Document root element is missing. Nested exception: Document root element is missing.
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
             .
          etc.
----------------------------------------------------------------------------------------
The unfortunate consequence is that every time this error comes up, I have to restart Tomcat, because if I don't this program will not run again, it will immediately terminates with exactly the same error message.
Can anyone please tell me what I am doing wrong, and, how can this problem be corrected?
Here are the two pieces of this program:
<%--
/*********************************************************
* CardHistory.jsp -                                                                                 *
*                                                                        AB -  10/21/2003          *  *********************************************************/
--%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/io-1.0" prefix="io" %>
<%@ taglib prefix="xtags" uri="http://jakarta.apache.org/taglibs/xtags-1.0" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %>

<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.lang.CharSetUtils" %>
<%!
/***************************************************************
** NOTE:  set itemsPerPage  for display                                  *
***************************************************************/
      int itemsPerPage = 20;
      int ix = 0;
%>
<!--******************************************-->
<!--**  NOTE: set url for this page          *-->
<!--******************************************--/
<pg:pager url="http://localhost:8080/CardHistory.jsp" index="half-full"
                     maxPageItems="<%=itemsPerPage%>"
               export="currentPageNumber=pageNumber, pageOffset">            


<%!
/**********************************************
** Getter Method for form properties         **
**********************************************/
public String getField(HttpServletRequest request,String fld)
{
      String value = request.getParameter(fld);
      
      return value == null ? "" : value;
}

public String getStartDate(HttpServletRequest request)
{
      String value = request.getParameter("fromDate");
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy");
    Calendar today = Calendar.getInstance();
   
    if (null == value) {
       String temp = sdf.format(today.getTime());
       value = temp.substring(0,3) + "01" + temp.substring(5,10);
       }
    return value;
}

public String getEndDate(HttpServletRequest request)
{
      String value = request.getParameter("thruDate");
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy");
    Calendar today = Calendar.getInstance();
   
    return value == null ? sdf.format(today.getTime()) : value;
 
 }
%>
<html>
<head>
<!-- ************************************************************-->
<!-- * NOTE: change href to point to the style sheet location ***-->
<!-- ************************************************************-->
<link rel="stylesheet" type="text/css" href="http://localhost:8080/css/card.css" />
<script>
      function validateInput(form)
      {
            if (form.PIN.value == "" || form.PAN == "")
            {
                  alert("invalid PAN/PIN");
                  return (false);
            }
            else
                  return (true)
      }

      function submitClick(ctrl,pageNumber)
      {
            QueryForm["pager.offset"].value = (pageNumber-1) * <%=itemsPerPage%>;

            return true;
      }
</script>

</head>
<body>
      <form method="post" name="QueryForm" onsubmit="return validateInput(QueryForm);">
      <div align="center">
      <center>
      <table border='0' cellspacing='0' cellpadding='3' width='80%'>
            <tr>
                  <td colspan="2"><img src="ginibank.jpg" width="140"></td>
                  <td class="label" align="left"><font color="336690" size="3"><strong>
                        Card Transaction Lookup<br><br></font>
                  </td>
            </tr>
      </table>
      <table border='0' cellspacing='0' cellpadding='3' width='80%'>            
            <tr valign='middle' width='20%'>
                  <td class="label" align="right"><font color="336690" size="2"><strong>
                        Card Number</strong></font></td>
                  <td  class="data" align="left">
                        <input type="text" name="PAN" value="<%= getField(request,"PAN") %>" size="30">
                  </td>
                  <td class="label" align="right"><font color="336690" size="2"><strong>
                        Password</strong></font></td>
                  <td class="data" align="left">
                        <input type="password" name="PIN" value="<%= getField(request,"PIN") %>" size="30" ID="Text1">
                  </td>
            </tr>
            <tr valign='middle' width='50%'>
                  <td class="label" align="right"><font color="336690" size="2"><strong>
                        From Date</strong></font></td>
                  <td  class="data" align="left">
                        <input type="text" name="fromDate" value="<%= getStartDate(request) %>" size="30">
                  </td>
                  <td class="label" align="right"><font color="336690" size="2"><strong>
                        Thru Date</strong></font></td>
                  <td class="data" align="left">
                        <input type="text" name="thruDate" value="<%= getEndDate(request) %>" size="30" >
                  </td>
            </tr>                  
            <tr valign=middle>
                  <td align=center colspan=4>
                        <input type="IMAGE" src="icnUpdate.gif" Name=Proess" Border="0" alt="Update" ID="Image1">
                  </td>      
            </tr>
      </table>
      </center>
      </div>

 <!---- Present the Card History ------->    
       
<% if (request.getParameter("PAN") != null && request.getParameter("PIN") != null) { %>
<!-- Do not change the name of this hidden field, it is used by the pager   -->
<input type="hidden" name="pager.offset" value=<%=pageOffset%> >
<!--************************************************************************-->
<!--* The following section generates the xml for the request              *-->
<!--* the io:body is the content of the XML, modify the contents as needed *-->
<!--* NOTE: change io:http url attribute if needed                         *-->
<!--************************************************************************-->
      <xtags:parse>
            <io:http url="https://cbbs.calnetbank.com/CBBService.asp" action="POST" input="true" output="true">
            <io:body>
                  <CBBRequest><Authentication><SignOnID>Easytel</SignOnID><Password>Password</Password></Authentication>
                  <Service ID="0"><Type>Card Management</Type><Name>GetCardBalance</Name><PAN><%=getField(request,"PAN")%></PAN><PIN><%=getField(request,"PIN")%></PIN></Service>
                  <Service ID="1"><Type>Card Management</Type><Name>GetCardHistory</Name><PAN><%=getField(request,"PAN")%></PAN><PIN><%=getField(request,"PIN")%></PIN>
                  <FromDate><%=getStartDate(request)%></FromDate>
                  <ToDate><%=getEndDate(request)%></ToDate></Service>
                  </CBBRequest>
            </io:body>
      </io:http>
      </xtags:parse>
      
      <!--**************************************************-->
      <!--* Check Service Status                           *-->
      <!--**************************************************-->
      
      <xtags:choose>
            <xtags:variable id="sumStatusCode" select="/CBBResponse/Summary/StatusCode" />
            <xtags:variable id="sumStatusMsg" select="/CBBResponse/Summary/StatusMessage" />
            <xtags:when test="$sumStatusCode != '0'" >
                  <div align=center class=label><font color=red>CBBS wrapper validation returned status code <%=sumStatusCode%>:<BR>
                  <%= sumStatusMsg %>
                  </font></div>
            </xtags:when>
            <xtags:otherwise>
                  <% boolean serviceFlag = true; %>
                  <xtags:forEach select="/CBBResponse/Service/StatusCode" >
                        <xtags:if test=".!= '0'" >
                              <div align=center class=label><font color=red>GetCardHistory returned status code  <xtags:valueOf select="."/>:<BR>
                                          <xtags:valueOf select="../Message" />
                              </font></div>
                              <% serviceFlag = false; %>
                              <xtags:break/>
                        </xtags:if>
                  </xtags:forEach>
                  <!--***********************************************-->
                  <!--* continue to display detail if no error found*-->
                  <!--***********************************************-->
                  <% if (serviceFlag) { %>
                        <%@include file="CardDetail.jsp" %>
                  <% } %>
            </xtags:otherwise>
      </xtags:choose>      
<%}%>
</pg:pager>
</form>
</body>
</html>


<!--**************************************************-->
<!--* Balance section                                *-->
<!--**************************************************-->
<xtags:variable id="balance" select="/CBBResponse/Service/Results/ResultsItem/Balance"/>
            <table align='center' border='0'>
                  <tr><td align="center">Current Balance:
                        <xtags:choose>
                              <xtags:when test="substring($balance,1,1) = '-'  ">
                                    <font color="#ff0000">
                              </xtags:when>
                              <xtags:otherwise>
                                    <font color="#000000">
                              </xtags:otherwise>
                        </xtags:choose>
                        <i18n:formatNumber value="<%=new Double(CharSetUtils.delete(balance,\",\"))%>" pattern="##,###,##0.00"/>
                        </font></td></tr>
      </table>

      
<!--*************************************************-->
<!--* History section                               *-->
<!--*************************************************-->
            <table bgcolor='#B5B5B5' align='center'width='92%' border=1 cellspacing=0><tr><th>&nbsp;</th><th>Post Date</th><th>Description</th><th>Amount</th></tr>
      
            <xtags:forEach select="/CBBResponse/Service/Results/ResultsItem/Amount" >
                  <pg:item><tr>
                      <%  
                          String cellColor = (ix % 2 == 0) ? "White" : "#E5E5E5";
                          ix++;
                      %>
                        <td bgcolor="<%=cellColor%>" align='right'><xtags:valueOf select="../TransactionID" /></td>
                        <td bgcolor="<%=cellColor%>" align='center'><xtags:valueOf select="../PostDate" /></td>
                        <td bgcolor="<%=cellColor%>" class=data align='left'><xtags:valueOf select="../Description" /></td>
                        <td bgcolor="<%=cellColor%>" align='right'>
                              <xtags:choose>
                                    <xtags:when test="starts-with(.,'-')">
                                          <font color="#ff0000">
                                    </xtags:when>
                                    <xtags:otherwise>
                                          <font color="#000000">
                                    </xtags:otherwise>
                              </xtags:choose>
                              <xtags:variable id="amount" select="." />
                              <!--xtags:valueOf select="." /-->
                              
                              <i18n:formatNumber value="<%=new Double(CharSetUtils.delete(amount,\",\"))%>" pattern="##,###,##0.00"/>
                              <!--xtags:variable id="amount" select="."/-->
                              <!--i18n:formatNumber value="<---%=new Double(amount) %>" pattern="0.00"/--></font></td>
                  </tr></pg:item>
            </xtags:forEach>
            </table>
            
            <!--*******************************************-->
            <!--*  pager section                          *-->
            <!--*******************************************-->
            <pg:index export="pageCount">
                <center>
                <table border=0 cellpadding=0  cellspacing=10>
                <tr align=center valign=top>
                                         
               
                <pg:prev ifnull="true">
                  <% if (pageUrl != null) { %>
                     <td align=center><input type="IMAGE" src="verbPreviousPage.gif" Name="Prev" Border="0" value="Prev" ID="Prev1" onClick='return submitClick(QueryForm.fwBackBtn,<%=currentPageNumber.intValue()-1%>);' ></td>
                  <% } %>
                 
                </pg:prev>
                <% if (pageCount.intValue() > 1) { %>
                      <td class="label" align="right"><font color="336690" size="2">Page</font></td>
                        <td  class="data" align="left">
                           <input type="text" name="gotoPage" value="<%= currentPageNumber.intValue() %>" size="2">
                        </td>
                      <td class="label" align="right"><font color="336690" size="2">of <%=pageCount%></font></td>
                      <td align=center><input type="submit" name="fwBackBtn" value="Go" onClick='return submitClick(QueryForm.fwBackBtn,QueryForm.gotoPage.value);' ></td>
                <%}%>
               
                <pg:next ifnull="true">
                  <% if (pageUrl != null) { %>
                     <td align=center><input type="IMAGE" src="verbNextPage.gif" Name="Next" Border="0" value="Next" ID="Next1" onClick='return submitClick(QueryForm.fwBackBtn,<%=currentPageNumber.intValue()+1%>);' ></td>
                  <% }  %>
            
                </pg:next>
               
               
</tr>
</table>
</center>
 </pg:index>
0
Comment
Question by:ablazso
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
It's not an ideal solution, but I would;

1) Allow users to see multiple pages (like google), so if they want to go to page 4, they can jump straight there -- there are examples of this in the pg taglib...
2) Disable buttons with javascript when they are clicked -- this will stop people clicking multiple times...
3) Try and catch the exception...  if it is caught, then reload the current page

Hmmm...sorry i can't be of much help :-(

Tim
0
 

Author Comment

by:ablazso
Comment Utility
Thanks for the advice Tim!  User can, even as is, enter a given page number and by pressing the "Go" button to jump to that page directly. However, I don't know how to disable buttons with javascript. Can you possible give me an example? Or, tell me where I can find one? Also, what part in my porgram, you suggest, should I try to catch the exception?
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 50 total points
Comment Utility
> However, I don't know how to disable buttons with javascript

this.disabled = true ;

or:

document.getElementById( "name of button" ).disabled = true ;

> Also, what part in my porgram, you suggest, should I try to catch the exception?

The exception you are getting is an invalid XML exception...

I would place the try catch round all of the code which uses xtags...

especially the xtags:parse bit?

Tim
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 250 total points
Comment Utility
I didn't see problem in your code. Most likely caused by bugs in URLConnection class and/or taglibs.

I prefer to handle those heavy process logic in java code in a Servlet instead of letting it to jsp and taglib.
0
 

Author Comment

by:ablazso
Comment Utility
I put it the error trap per your suggested, it resulted some additional error message:
-----------------
org.dom4j.DocumentException: Error on line 1 of document  : Document root element is missing. Nested   exception: Document root element is missing.at org.dom4j.io.SAXReader.read(SAXReader.java:330) at org.dom4j.io.SAXReader.read(SAXReader.java:249) at org.apache.taglibs.xtags.xpath.ParseTag.doAfterBody(ParseTag.java:1380)
----------------
however, this does not solve my problem. What I think I need is a sure way to prevent a new 'onClick' action to happen until the first one is completed. After all the damn thing works if the user is patient!
I tried to implement you other suggestions:

  this.disabled = true ;
  or:
  document.getElementById( "name of button" ).disabled = true ;

but, I failed. Would you be so kind to tell me where in the code they should be implemented?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:ablazso
Comment Utility
Sorry! The first sentence above should have started like this:
I put in the error trap....
0
 
LVL 3

Assisted Solution

by:krispols
krispols earned 200 total points
Comment Utility
hello ablazso,

Disabled the button with javascript will not resolve your problem, cause if the user open two browsers, he could send you to request like a double click. The pattern usually used to bypass this problem is to use a session token.
You must have a unique number in your session, then in your jsp page you set an hidden field with this number. When a user submit the page, you check the hidden field with the session number.
1/ if it's the same, you increment the unique number and process the request.
2/ if it's different, you redirect to the entry pae or error page as you want.

I join the  kennethxu remark about put this kind of process in a servlet.

regards
0
 

Author Comment

by:ablazso
Comment Utility
Boy, you are way over my head with this!
Perhaps you could send me a sample code that exemplifies your suggestion?
I'd very much appreciate it.

Thanks,

ablazso
0
 

Author Comment

by:ablazso
Comment Utility
Can anyone help me with this?  PLEASE!!!!
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
Thanks for the A grade! does the link help?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now