Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Error Processing JSP Page  RSS feed

 
Benita Perkins
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

In case this has already been discussed, please could you point me to the right place but I have looked pretty much everywhere and I haven't found the answer to my issue. It's driving me nuts!! Any advise, direction, help or comments are greatly welcomed and appreciated.

I have a jsp and when I run it I get the following error:

HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /docs/delete_docs.jsp at line 4

1: <jsp:useBean id="doc" class="cca.beans.docs_bean" scope="page"/>
2: <jsp:useBean id="st" class="cca.beans.Settings" scope="page"/>
3:
4: <% if (request.getParameter("type").compareTo("special") != 0 ) {%>
5:
6: String strLevel = session.getAttribute("status_level").toString();
7: String delfile = null;


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
org.apache.jsp.docs.delete_005fdocs_jsp._jspService(delete_005fdocs_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

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


The closest I could find was a thread on the struts forum but it doesn't clear much up.
I have the same code running in another jsp and it works fine so I'm stumped!

This is the code:
<jsp:useBean id="doc" class="cca.beans.docs_bean" scope="page"/>
<jsp:useBean id="st" class="cca.beans.Settings" scope="page"/>

<% if (request.getParameter("type").compareTo("special") != 0 ) {%>

String strLevel = session.getAttribute("status_level").toString();
String delfile = null;
//if(strLevel.compareTo("-2") != 0 && strLevel.compareTo("1") != 0 && strLevel.compareTo("2") != 0)
//{
// %><!--<script language="javascript">window.open("http://10.0.0.7/TWG_HO/GenLogon.asp","_parent");</script>--><%
//}
}

// Check to see if the folder exists
String str = doc.CheckFolder(request.getParameter("regno"));
boolean bMissing = false;
if (str.compareTo("Missing") == 0)
{
bMissing = true;
}
%>

<html>
<head>
<link rel="StyleSheet" href="../style/Standard.css" type="text/css">
</head>

<% if (request.getParameter("type").compareTo("special") != 0 )
{%>

<SCRIPT SRC="../menu/ssm.js" language="JavaScript1.2"></SCRIPT>
<SCRIPT SRC="../menu/ssmItems<%=session.getAttribute("status_level")%>.js" language="JavaScript1.2"></SCRIPT>
<%}%>

<body>
<table class="Outer"> <tr ><td> <table class="Inner"> <% if (bMissing) {%> <tr><td>No documents linked to <%=request.getParameter("cmpyname")%> branch <%=request.getParameter("branch")%></td></tr> <% } else { %> <tr class="Heading"><td >View documents for <%=request.getParameter("cmpyname")%> branch <%=request.getParameter("branch")%></td></tr> <% // check scan on file docs String strNumber = doc.CheckNumberOfFiles(request.getParameter("regno"), "scan"); // Get the last number if (strNumber.startsWith("Application Error")) // If an application error occured { session.setAttribute("Error_Variable",strNumber); %><script language="javascript">window.open("../ErrorPage.jsp?ErrorLocation=display_docs1","_parent");</script><% } else { Integer Int = new Integer(0); Int = Int.valueOf(strNumber); // Convert to Integer int iNumber = Int.intValue() ; // New number %><tr class="Heading"><td>Scan on file</td></tr><% // Write links to file for(int i = 1; i < iNumber + 1; i++) { //delfile="PF1_199000689707.pdf"; //delfile="../uploaded_docs/" + request.getParameter("regno") + "/SC" + new Integer(i).toString() + "_" + request.getParameter("regno") + ".pdf"%> %><tr class="Part1_A"><td>Scan on file <%=new Integer(i).toString()%></td></tr><% } } // check profile on file docs strNumber = doc.CheckNumberOfFiles(request.getParameter("regno"), "profile"); // Get the last number if (strNumber.startsWith("Application Error")) // If an application error occured { session.setAttribute("Error_Variable",strNumber); %><script language="javascript">window.open("../ErrorPage.jsp?ErrorLocation=display_docs2","_parent");</script><% } else { Integer Int = new Integer(0); Int = Int.valueOf(strNumber); // Convert to Integer int iNumber = Int.intValue() ; // New number %><tr class="Heading"><td>Profile on file</td></tr><% // Write links to file for(int i = 1; i < iNumber + 1; i++) { %><tr class="Part2_A"><td>" target="_new">Profile on file <%=new Integer(i).toString()%></td></tr><% } } // check consumer profile strNumber = doc.CheckNumberOfFiles(request.getParameter("regno"), "consumer"); // Get the last number if (strNumber.startsWith("Application Error")) // If an application error occured { session.setAttribute("Error_Variable",strNumber); %><script language="javascript">window.open("../ErrorPage.jsp?ErrorLocation=display_docs3","_parent");</script><% } else { Integer Int = new Integer(0); Int = Int.valueOf(strNumber); // Convert to Integer int iNumber = Int.intValue() ; // New number %><tr class="Heading"><td>Consumer profile</td></tr><% // Write links to file for(int i = 1; i < iNumber + 1; i++) { %><tr class="Part2_A"><td>" target="_new">Consumer profile <%=new Integer(i).toString()%></td></tr><% } } }%> <tr><td ><input type="button" value="Back" onClick="Back()" class="BT"></td></tr> </table> </td></tr> </table>
</form>
</body>

<script language="javascript">
function Back()
{
var dt = new Date();
<% if (request.getParameter("type").compareTo("special") == 0 )
{%>
window.open("../special/Display_one_record.jsp?dt2=" + dt + "&" +"<%=request.getQueryString()%>","_parent");
<%} else {%>
window.open("../data_jsp/Display_one_record.jsp?cca_key=<%=request.getParameter("cca_key")%>&field=<%=request.getParameter("field")%>&value=<%=request.getParameter("value")%>&type=<%=request.getParameter("type")%>" + "&dt=" + dt,"_parent");
<%}%>
}
</script>

</html>

Thanks
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benita Perkins wrote:
4: <% if (request.getParameter("type").compareTo("special") != 0 ) {%>
5:
6: String strLevel = session.getAttribute("status_level").toString();
7: String delfile = null;


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
org.apache.jsp.docs.delete_005fdocs_jsp._jspService(delete_005fdocs_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



Its hard to understand the code, if they are not surrounded by code tag.

And most possibly, the error is due to not finding parameter "type" in request object.


So check for its 'nullablity'
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the problem is obvious. The statement

request.getParameter("type")

is returning null. So when you try to call compareTo on a null reference, then you get NPE. There is no direct solution to this. The request doesn't have a type parameter that's it. Either the calling page misses a field type or you may have a typo in the calling page i.e. you may have typed tyype or something in the calling JSP or HTML page or whatever...
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% if (request.getParameter("type").compareTo("special") != 0 ) {%>


What will happen if request.getParameter("type") returns a null, the compareTo method will be called on a null reference thus causing nullpointerexception.

So you should either check that reference that it is not null before calling the method for e.g.

if(request.getParameter("type")!=null && request.getParameter("type").compareTo("special") != 0)

or you should call the method on the reference which can never be null for e.g.

if("special".compareTo(request.getParameter("type")!=0)
 
Benita Perkins
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there.

Sorry about the Code Tags Sagar.... I'll remember to use them in future.

Thanks for the tips - I'll check the call to see what it is returning!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!