This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes Exception in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Exception in JSP" Watch "Exception in JSP" New topic
Author

Exception in JSP

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
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?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
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

Joined: Jun 08, 2008
Posts: 214
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Did you read the FAQ I linked to?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in JSP
 
Similar Threads
Gettinh Exception in JSP
page refresh problem
Display error message in div tag
Display error when record not found
tomcat crashes when counting lines in a text file