We help IT Professionals succeed at work.
Get Started

JSP Error:  java.lang.NullPointerException

FrostyGirl
FrostyGirl asked
on
1,236 Views
Last Modified: 2014-04-04
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

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE