troubleshooting Question

JSP Error: java.lang.NullPointerException

Avatar of FrostyGirl
FrostyGirlFlag for United States of America asked on
JSPJava
8 Comments1 Solution1246 ViewsLast Modified:
Hi, I'm going to post the code below for this error.  Basically I'm new to JSP and I'm been given the task to fix this broken application.  Whenever I go to post a <form>, I receive this error:

org.apache.jasper.JasperException
&#9;org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
&#9;org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
&#9;org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause

java.lang.NullPointerException
&#9;com.monumental.trampoline.utilities.forms.multipart.MultipartRequest.getFile(MultipartRequest.java:72)
&#9;org.apache.jsp.admin.productfamilies.process_005fnavigation_jsp._jspService(process_005fnavigation_jsp.java:205)
&#9;org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
&#9;org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
&#9;org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
&#9;org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
&#9;javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Here is the form page:

<%@ page language="java" %>
<%@ page import="com.monumental.trampoline.component.*" %>
<%@ page import="com.monumental.trampoline.navigation.*" %>
<%@ page import="com.monumental.trampoline.security.*" %>
<%@ page import="com.monumental.trampoline.content.*" %>
<%@ page import="com.vdlm.productfamilies.*" %>
<jsp:useBean id="dbResources" class="com.monumental.datasources.rdbms.DbResources" />
<jsp:useBean id="userbean" class="com.monumental.trampoline.security.UserBean" />
<jsp:useBean id="navbean" class="com.vdlm.productfamilies.ProductFamilyNavigationCacheBean" />
<% userbean.init(pageContext, dbResources); %>
<% userbean.onlyUsers( "../reload.jsp"); %>
<% CompProperties props = new CompProperties(); %>
<%
boolean add = false;
boolean edit = false;
boolean delete = false;
Permission permission = new Permission();
User user = userbean.getUser();
if( user.getGroup().hasData() ) {
	permission = user.getGroup().getPermission( new ProductFamilyNavigation() );
	}
if(permission.getAdd()) {
	add = true;
	}
if(permission.getEdit()) {
	edit = true;
	}
if(permission.getDelete()) {
	delete = true;
	}
%>
<%
int currentNavId = 0;
if(request.getParameter(ProductFamilyNavigation.PARAM)!=null) {
	currentNavId = Integer.parseInt(request.getParameter(ProductFamilyNavigation.PARAM));
} else if(session.getAttribute("currentNavId")!=null) {
	currentNavId = ((Integer)session.getAttribute("currentNavId")).intValue();
	}
session.setAttribute("currentNavId",new Integer(currentNavId));
%>
<%
navbean.init(pageContext, dbResources);



ProductFamilyNavigationCache navcache = navbean.getCache();
CompEntities navigations = navcache.getAllSubNavigations(currentNavId);
CompEntities navigations2 = navcache.getTree();
ProductFamilyNavigation navigation;
ProductFamilyNavigation tempNav;

TemplateCache tempcache = new TemplateCache(dbResources,props.getAdminConfiguration());
TemplateController tempcontrol = new TemplateController(dbResources,props.getAdminConfiguration());
CompEntities templates2 = tempcontrol.getTemplates( true );
Template template;
CompEntities templates = new CompEntities();
while(templates2.hasNext()) {
	template = (Template)templates2.next();
	template = (Template)tempcache.getTemplate(template.getId());
	templates.add(template);
}

ProductFamilyNavigation thisnav = navcache.getNavigation(currentNavId);
CompEntities hier = null;
if(thisnav!=null) {
	hier = navcache.getNavigationHierarchy(thisnav);
	}	
dbResources.close();
%>
<% int indent = 1; %>
<%
String restrict = "";
boolean restricted = false;
Content content = null;
if(request.getParameter("restrict") != null) { 
		restrict = request.getParameter("restrict");
		restricted = true;
		Class myClass = Class.forName(restrict);
		content = (Content)myClass.newInstance();
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<title></title>
<style type="text/css">
@import url(../common/main.css);
</style>
</head>
<body>
<div id="bodycontent">
<% int tabindex = 1; %>
<div id="addnavigation">
	<form method="post" action="process_navigation.jsp" id="contentform" enctype="multipart/form-data">
		<fieldset>
			<legend>add a category</legend>
			<label for="<%= ProductFamilyNavigation.NAME_COLUMN %>">name:</label>
			<input type="text" size="50" id="<%= ProductFamilyNavigation.NAME_COLUMN %>" name="<%= ProductFamilyNavigation.NAME_COLUMN %>" tabindex="<%=tabindex++%>"/>
			<br />				
			<label for="<%= ProductFamilyNavigation.DESCRIPTION_COLUMN %>">description:</label>
			<input type="text" size="50" id="<%= ProductFamilyNavigation.DESCRIPTION_COLUMN %>" name="<%= ProductFamilyNavigation.DESCRIPTION_COLUMN %>" tabindex="<%=tabindex++%>"/>
			<br />
			<label for="<%= ProductFamilyNavigation.PICTURE_COLUMN %>">picture:</label>
			<input type="file" id="<%= ProductFamilyNavigation.PICTURE_COLUMN %>" name="<%= ProductFamilyNavigation.PICTURE_COLUMN %>" tabindex="<%=tabindex++%>" />
			<br />
			<input type="hidden" name="action" value="add" />
			<input type="hidden" name="<%= ProductFamilyNavigation.PARENT_ID_COLUMN %>" value="<%= currentNavId %>" />			
			<input class="submit" type="submit" name="submit" value="create" tabindex="<%=tabindex++%>" />
		</fieldset>
	</form>
	</div>
	
	
	<div id="currentnavigations">
		<h1 id="currentnavigationsheader">category hierarchy</h1>
		<span class="toplevelnavigation"><a href="navigation.jsp?<%= ProductFamilyNavigation.PARAM %>=0">Top Level</a>
		<% if(hier!=null) { %>
			<% while(hier.hasNext()) { %>			
				<% navigation = (ProductFamilyNavigation)hier.next(); %>
					: <a class="<% if(!navigation.isActive()) { %>inactive<% } %>nav" href="navigation.jsp?<%= ProductFamilyNavigation.PARAM %>=<%= navigation.getId() %>"><%= navigation.getName() %></a>
			<% } %>
		<% } %>	
		</span>
		
		<% Template navTemplate; %>
		<% boolean navON = true; %>
		<% if(navigations.howMany() > 0) { %>
		<div id="currentnavcontainer">       			
			<% for(int x=0; x<navigations.howMany();x++) { %> 
				<% navigation = (ProductFamilyNavigation)navigations.get(x); %>
				<% navTemplate = navigation.getTemplate(); %>
				<%
				if(restricted) {
				if (navTemplate==null || !navTemplate.canContainContent(content)) {
					navON = false;
				} else {
					navON = true;
				}
				}
				%>
				<div class="singlenav">
					<span class="navheader">
						<a class="<% if(!navigation.isActive()) { %>inactive<% } %>navigation" href="navigation.jsp?<%= ProductFamilyNavigation.PARAM %>=<%= navigation.getId() %>"><%= navigation.getName() %><% if(navigation.isLink()) { %>&nbsp;&nbsp;<--links to another navigation--><% } %></a>
					</span>
					<form method="get" action="process_navigation.jsp" class="navposition">
						<select name="<%= ProductFamilyNavigation.POSITION_COLUMN %>" tabindex="<%=tabindex++%>">		
						<% for(int y=0; y<navigations.howMany();y++) { %> 
							<% tempNav = (ProductFamilyNavigation)navigations.get(y); %>
							<option value="<%= y+1 %>" <% if(tempNav.getId()==navigation.getId()) { %>selected<% } %>><%= y+1 %></option>
						<% } %>
						</select>
						<input type="hidden" name="<%= ProductFamilyNavigation.PARAM %>" value="<%= navigation.getId() %>" />
						<input type="hidden" name="action" value="order" />
						<input class="submit" type="submit" value="set order" tabindex="<%=tabindex++%>"  <% if(!navON) { %>style="visibility: hidden;"<% } %>/>
					</form>	
					<form method="get" action="process_navigation.jsp" class="navstatus">
						<select name="<%= ProductFamilyNavigation.STATUS_COLUMN %>" tabindex="<%=tabindex++%>">			
							<option><% if(navigation.isActive()) { %>active<% } else { %>inactive<% } %></option> 
							<option value="<% if(navigation.isActive()) { %>active<% } else { %>inactive<% } %>">-----</option>
							<option>active</option>
							<option>inactive</option>
						</select>	
						<input type="hidden" name="<%= ProductFamilyNavigation.PARAM %>" value="<%= navigation.getId() %>" />
						<input type="hidden" name="action" value="status" />
						<input class="submit" type="submit" value="set status" tabindex="<%=tabindex++%>" <% if(!navON) { %>style="visibility: hidden;"<% } %>/>
					</form>				
					<form method="get" action="navigation_details.jsp" class="navparent">
						<input type="hidden" name="<%= ProductFamilyNavigation.PARAM %>" value="<%= navigation.getId() %>" />
						<input class="submit" type="submit" value="more options"  tabindex="<%=tabindex++%>" <% if(!navON) { %>style="visibility: hidden;"<% } %>/>
					</form>														
					<br />					
				</div>
			<% } %>	
		</div>
		<% } %>		
	</div>
</div>

Open in new window

ASKER CERTIFIED SOLUTION
rikaz

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros