• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in JSP

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a hibernet application an in that i have "index.jsp" which is as follows:

<%--
Document : index
Created on : 3 Jun, 2008, 10:09:45 AM
Author : Frank J
--%>

<%@page import="dvdrental.*"%>
<%@page import="java.util.List"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>DVD Rental</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="header.jsp" %>

<div id="content">
<div id="colOne">
<%
int startID = 1;
int endID = 10;
int prev_startID =1;
int prev_endID = 10;
int filmTitlesSize = 0;

int FILM_RECORD_COUNT = 1000;

boolean RECORD_START_PAGE = false;
boolean RECORD_END_PAGE = false;

if (request.getParameter("startid") != null) {
startID = Integer.parseInt(request.getParameter("startid"));
}
if (request.getParameter("endid") != null) {
endID = Integer.parseInt(request.getParameter("endid"));
}

FilmHelper helper = new FilmHelper();
List filmTitles = helper.getFilmTitles(startID, endID);

if(startID == 1){
RECORD_START_PAGE = true;
}
if(endID == FILM_RECORD_COUNT){
RECORD_END_PAGE = true;
}

prev_startID = startID-10;
prev_endID = endID-10;

startID = endID + 1;
endID = endID + 10;

filmTitlesSize = filmTitles.size();

out.print("<table>");

if(RECORD_START_PAGE){
out.print("<tr><td class='NEXT'> </td><td class='NEXT'> </td><td class='NEXT'> </td><td class='NEXT'><a class='RENT' href=\"index.jsp?startid="+startID+"&endid="+endID+"\">Next</a></td></tr>");
}
else if(RECORD_END_PAGE){
out.print("<tr><td class='NEXT'> </td><td class='NEXT'> </td><td class='NEXT'><a class='NEXT' href=\"index.jsp?startid="+prev_startID+"&endid="+prev_endID+"\">Prev</a></td><td class='NEXT'> </td></tr>");
}else{
out.print("<tr><td class='NEXT'> </td><td class='NEXT'> </td><td class='NEXT'><a class='NEXT' href=\"index.jsp?startid="+prev_startID+"&endid="+prev_endID+"\">Prev</a></td><td class='NEXT'><a class='NEXT' href=\"index.jsp?startid="+startID+"&endid="+endID+"\">Next</a></td></tr>");
}

out.print("<tr><th>Title</th><th>Description</th><th> </th><th> </th></tr>");
for (int i = 0; i < filmTitlesSize; i++) {
Film film = (Film) filmTitles.get(i);
int filmID = film.getFilmID();
out.print("<tr>");
out.print("<td class='COL1'><a href=\"browse.jsp?id=" + filmID + "\">" + film.getTitle() + "</a></td>");
out.print("<td class='COL2'>" + film.getDescription() + "</td>");
out.print("<td class='COL2'><a href=\"browse.jsp?id=" + filmID + "\">More</a></td>");
out.print("<td class='COL2'><a href=\"rent.jsp?id=" + filmID + "\">Rent</a></td>");
out.print("</tr>");
}
out.print("</table>");
%>

</div>

</div>
<%@ include file="footer.jsp" %>
</body>
</html>



But when i try to run that application i got following exception:


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 /index.jsp at line 62

59: startID = endID + 1;
60: endID = endID + 10;
61:
62: filmTitlesSize = filmTitles.size();
63:
64: out.print("<table>");
65:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


root cause

java.lang.NullPointerException
org.apache.jsp.index_jsp._jspService(index_jsp.java:126)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


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


Can any one please advice me to resolve this problem?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to find out why "helper.getFilmTitles(startID, endID)" returns null.

The first step in diagnosing any NullPointerException is to find out which object is null. Then you can investigate why it is null, when you were expecting it not to be.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf thanks for your advice!!!

following is the function

public List getFilmTitles(int startID, int endID) {
List filmList = null;
try {
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Film as film where film.filmID between '"+startID+"' and '"+endID+"'");
filmList = q.list();

} catch (Exception e) {
e.printStackTrace();
}
return filmList;
}


How can i avoid getting null or what conditions should be added if require?
 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear you are right. But when i paste the code in the Message windoe it showed me the indented code (code with proper indent) which also looks easy to read and debug but i don't know how it looked difficult to read / debug when i posted it? Please advice me on this also. thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read the FAQ I linked to?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to figure out why it returns null. Are there any results it should be returning for whatever startID and endID you're passing in? Maybe the Hibernate code throws an exception?
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic