abooysen2
asked on
JSP CODE ERROR
Hi experts
I busy working on a old project but there is a part in the jsp page that causes and Error
2010-08-17 13:19:57,640 ERROR [org.apache.catalina.core. ContainerB ase.[jboss .web].[loc alhost].[/ mmticket]. [jsp]] (http-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception
java.lang.NullPointerExcep tion
at org.apache.jsp.main_jsp._j spService( main_jsp.j ava:968)
at org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:70)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
at org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 69)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:322)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:249)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 717)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:290 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at org.jboss.web.tomcat.filte rs.ReplyHe aderFilter .doFilter( ReplyHeade rFilter.ja va:96)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:235 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:2 06)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:235)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:191)
at org.jboss.web.tomcat.secur ity.Securi tyAssociat ionValve.i nvoke(Secu rityAssoci ationValve .java:190)
at org.apache.catalina.authen ticator.Au thenticato rBase.invo ke(Authent icatorBase .java:525)
at org.jboss.web.tomcat.secur ity.JaccCo ntextValve .invoke(Ja ccContextV alve.java: 92)
at org.jboss.web.tomcat.secur ity.Securi tyContextE stablishme ntValve.pr ocess(Secu rityContex tEstablish mentValve. java:126)
at org.jboss.web.tomcat.secur ity.Securi tyContextE stablishme ntValve.in voke(Secur ityContext Establishm entValve.j ava:70)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:127 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:102 )
at org.jboss.web.tomcat.servi ce.jca.Cac hedConnect ionValve.i nvoke(Cach edConnecti onValve.ja va:158)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :109)
at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:330)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:829)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocess(Http 11Protocol .java:598)
at org.apache.tomcat.util.net .JIoEndpoi nt$Worker. run(JIoEnd point.java :447)
I busy working on a old project but there is a part in the jsp page that causes and Error
2010-08-17 13:19:57,640 ERROR [org.apache.catalina.core.
java.lang.NullPointerExcep
at org.apache.jsp.main_jsp._j
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.jboss.web.tomcat.filte
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.jboss.web.tomcat.secur
at org.apache.catalina.authen
at org.jboss.web.tomcat.secur
at org.jboss.web.tomcat.secur
at org.jboss.web.tomcat.secur
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.jboss.web.tomcat.servi
at org.apache.catalina.core.S
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
<%
ArrayList arrClients = deal.getClients();
String client = request.getParameter("clients");
if(client==null) { client=""; }
String clientApostrophe = client;
if (clientApostrophe.indexOf("'") > -1) clientApostrophe = TicketUtils.addAposEscape(clientApostrophe);
%>
<select name="clients"
onchange="clientOnChange()"
>
<option value=""/>
<% for (int i=0; i<arrClients.size(); i++)
{
String strVal = (String) arrClients.get(i);
if (client.equals(strVal))
{
%>
<option value="<%=strVal%>" selected="selected"><%=strVal%></option>
<%
}
else
{
%>
<option value="<%=strVal%>"><%=strVal%></option>
<%
}
}
%>
</select>
</td>
<br>
<%
client = request.getParameter("clients");
ArrayList arrClientAccounts = deal.getAccountsByClient(client);
String account = request.getParameter("account_number");
if(account==null) account="";
%>
ASKER
I place this in the psj code and when i reached my second line i go this error
14:28:55,951 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerExcep tion
at org.apache.jsp.main_jsp._j spService( main_jsp.j ava:950)
ArrayList arrClients = new ArrayList();
System.out.println("This is empty" + deal.getClients());
arrClients = deal.getClients();
if(deal.getClients() == null){
System.out.println("This is empty" + deal.getClients());
}
14:28:55,951 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerExcep
at org.apache.jsp.main_jsp._j
ArrayList arrClients = new ArrayList();
System.out.println("This is empty" + deal.getClients());
arrClients = deal.getClients();
if(deal.getClients() == null){
System.out.println("This is empty" + deal.getClients());
}
ASKER
I event tries this
ArrayList arrClients = new ArrayList();
if(deal.getClients() == null){
System.out.println("This is empty" + deal.getClients());
}else{
System.out.println("Someth ing" + deal.getClients());
}
when it gets to deal.getClients() == null it throws the same error given above
ArrayList arrClients = new ArrayList();
if(deal.getClients() == null){
System.out.println("This is empty" + deal.getClients());
}else{
System.out.println("Someth
}
when it gets to deal.getClients() == null it throws the same error given above
ASKER
to give you a breakdown
the Deal.java
has
public abstract ArrayList getClients()
throws RemoteException;
the Deal.java
has
public abstract ArrayList getClients()
throws RemoteException;
ASKER
I even tried this
ArrayList arrClients = new ArrayList();
still does not work??
ArrayList arrClients = new ArrayList();
still does not work??
ASKER
i changed the code to
<%
ArrayList arrClients = deal.getClients();
String client = request.getParameter("clie nts");
if (client == null) {
client = "";
}
String clientApostrophe = client;
if (clientApostrophe.indexOf( "'") > -1)
clientApostrophe = TicketUtils.addAposEscape( clientApos trophe);
%>
but when it get to ArrayList arrClients = deal.getClients(); it just fails
can you perhaps assist
<%
ArrayList arrClients = deal.getClients();
String client = request.getParameter("clie
if (client == null) {
client = "";
}
String clientApostrophe = client;
if (clientApostrophe.indexOf(
clientApostrophe = TicketUtils.addAposEscape(
%>
but when it get to ArrayList arrClients = deal.getClients(); it just fails
can you perhaps assist
You're not checking if 'deal'is null
ASKER
when I debug arrCLients and just placed my mouse on arrClient is see this
ArrayList arrClients - main._jspService(HttpServl etRequest, HttpServletResponse)
What does this means?
ArrayList arrClients - main._jspService(HttpServl
What does this means?
ASKER
I check deal is null. But I have attached the code below.
Could this be the reason
<%!private Deal deal = null;%>
I am not sure why the previews developer did this. Is there a way to work around this.
Could this be the reason
<%!private Deal deal = null;%>
I am not sure why the previews developer did this. Is there a way to work around this.
<%@ page
import="deal.Deal,deal.DealHome,util.*,java.util.ArrayList,javax.ejb.*,java.math.*,java.text.*,java.net.*,javax.naming.*,java.util.*,java.lang.*,java.io.*,javax.rmi.PortableRemoteObject,java.rmi.RemoteException"
session="true"%>
<%!private Deal deal = null;%>
<%@page import="org.apache.commons.collections.iterators.ArrayListIterator"%><HTML>
<HEAD>
<TITLE>MMTicket</TITLE>
<script type="text/javascript">
//Function to get accounts based on client selected
function clientOnChange()
{
var selectedIndex = document.accounts.clients.selectedIndex;
var selectedClient = document.accounts.clients.options[selectedIndex].value;
document.accounts.clients.value = selectedClient;
document.accounts.account_number.value = "";
document.accounts.submit();
}
//Function to get account details based on account selected
function accountOnClick(client,accountNumber,accountStruct,accountType)
{
document.accounts.clients.value = client;
document.accounts.account_number.value = accountNumber;
document.accounts.account_structure.value = accountStruct;
document.accounts.account_type.value = accountType;
document.accounts.submit();
}
//handle buttons
function doDeal(client,accountNumber,dealType,accStruct,newOrExists)
{
<%session.setAttribute("deal", deal);%>
//set the deal type to be exactly either DEPOSIT or WITHDRAWAL to simplify processing in forms its forwarded to
if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
dealType="DEPOSIT";
if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
dealType="WITHDRAWAL";
client = client.replace('&','*');
var param = "";
param += addParam("client",client);
param += "&" +addParam("account_number",accountNumber);
param += "&" + addParam("deal_type",dealType);
param += "&" + addParam("acc_struct",accStruct);
param += "&" + addParam("new_or_exists",newOrExists);
CallServlet("deal.jsp",param, dealType);
document.accounts.submit();
}
//handle interdiv button
function doInterDiv(dealId, dealType, client)
{
<%session.setAttribute("deal", deal);%>
var param = "";
param += addParam("deal_id",dealId);
param += "&" + addParam("deal_type",dealType);
param += "&" + addParam("client",client);
CallServlet("interdiv.jsp",param,dealType);
document.accounts.submit();
}
//handle amend button
function doAmend(dealId, client,accountNumber,dealType,accStruct,newOrExists)
{
<%session.setAttribute("deal", deal);%>
if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
dealType="DEPOSIT";
if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
dealType="WITHDRAWAL";
if (dealType.toUpperCase().indexOf("DEPOSIT") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1 || dealType.toUpperCase().indexOf("LOAN") > -1)
{
client = client.replace('&','*');
var param = "";
param += addParam("client",client);
param += "&" +addParam("account_number",accountNumber);
param += "&" + addParam("deal_type",dealType);
param += "&" + addParam("acc_struct",accStruct);
param += "&" + addParam("new_or_exists",newOrExists);
param += "&" + addParam("is_amend","true");
//add deal_id for the case that this is an amend deal
param += "&" + addParam("deal_id",dealId);
CallServlet("deal.jsp",param, dealType);
}
else if (dealType.toUpperCase().indexOf("TRANSFER") > -1 && dealType.toUpperCase().indexOf("INTERDIV") > -1)
{
var param = "";
param += addParam("deal_id",dealId);
param += "&" + addParam("deal_type",dealType);
param += "&" + addParam("client",client);
CallServlet("interdiv.jsp",param,dealType);
}
document.accounts.submit();
}
//handle cancel button
function doCancel(dealId, dealType)
{
var msg;
if (dealType.toUpperCase().indexOf("RATE") > -1)
msg = "Are you sure you want to cancel deal "+dealId+"?\n. Please check the account rate after the change and ensure it's as intended.";
else
msg = "Are you sure you want to cancel deal "+dealId+"?";
if (confirm(msg))
{
<%session.setAttribute("deal", deal);%>
if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
dealType="DEPOSIT";
if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
dealType="WITHDRAWAL";
var param = "";
param += addParam("deal_id",dealId);
param += "&" + addParam("deal_type",dealType);
CallServlet("CancelDeal",param,"Cancel");
}
document.accounts.submit();
}
</script>
</HEAD>
<%@ include file="general.jsp"%>
<%@ include file="comboBox.jsp"%>
<BODY bgcolor=white>
<table border=0 align=center width=100%>
<tr>
<td colspan=3 align=left><img src="images/InvestecLogo.gif"
alt="Investec"></td>
</tr>
<tr>
<td colspan=3 style="font-family: arial; color: navy; font-size: 16"
align=center><b>Account and Deal Manager</b></td>
</tr>
<tr>
<td style="font-family: arial; font-color: blue; font-size: 9"
align=right><a href="logoff.jsp">Log off</a></td>
</tr>
</table>
<form name="accounts">
<%
String user = request.getRemoteUser();
%>
<table>
<tr>
<td><a style="font-family: arial; font-size: 13">Select
Client:</a></td>
<td><input size=23
onkeyup="return combo_keyup(this,document.accounts.clients, event)"
onkeydown="return combo_keydown(document.accounts.clients, event)"
onkeypress="return combo_keypress(this,document.accounts.clients, event);" />
</td>
<td style="font-family: arial; font-color: navy; font-size: 12">
<a href="new_client.jsp">New Client / Account </a></td>
<td />
<td />
<td style="font-family: arial; font-color: navy; font-size: 12">
<a href="ticketsearch.jsp">Deal Search </a></td>
</tr>
<tr>
<td />
<td>
<%
ArrayList arrClients = new ArrayList();
if(deal == null){
System.out.println(" deal is null" + deal);
}else{
System.out.println("deal is not null" + deal);
}
//deal.getClients();
System.out.println(arrClients);
String client = request.getParameter("clients");
if (client == null) {
client = "";
}
String clientApostrophe = client;
if (clientApostrophe.indexOf("'") > -1)
clientApostrophe = TicketUtils.addAposEscape(clientApostrophe);
%>
<select name="clients" onchange="clientOnChange()">
<option value="" />
</select></td>
<br>
<input name="account_number" type=hidden />
<input name="account_structure" type=hidden />
<input name="account_type" type=hidden />
<table border=0 align=center width=650>
<caption align=right><b
style="font-family: arial; font-size: 14">All accounts<b></caption>
<tr bgcolor=navy>
<td width=150 align=left
style="font-family: arial; font-size: 12; color: white">Account</td>
<td width=100 align=left
style="font-family: arial; font-size: 12; color: white">Account
type</td>
<td width=100 align=left
style="font-family: arial; font-size: 12; color: white">Account
structure</td>
<td width=100 align=right
style="font-family: arial; font-size: 12; color: white">Balance</td>
<td width=100 align=right
style="font-family: arial; font-size: 12; color: white">Rate</td>
<td width=100 align=right
style="font-family: arial; font-size: 12; color: white">Interest</td>
</tr>
<tr>
<td colspan=6>
<div style="overflow: auto; width: 650; height: 120;"></div>
</td>
</tr>
<tr>
<td />
<td />
<td />
</tr>
</table>
<table align=center>
<tr />
<tr>
<td><input type=button name='butcalldeposit'
value='New Call Deposit ' /></td>
<td><input type=button name='butcallloan'
value='New Call Loan ' /></td>
<td><input type=button name='butfixeddeposit'
value='New Fixed Deposit' /></td>
<td><input type=button name='butfixedloan'
value='New Fixed Loan ' /></td>
<td><input type=button name='butfixeddeposit'
value='New Fixed Deposit' /></td>
<td><input type=button name='butfixedloan'
value='New Fixed Loan ' /></td>
<td><input type=button name='butfixeddeposit'
value='New Fixed Deposit' /></td>
<td><input type=button name='butfixedloan'
value='New Fixed Loan ' /></td>
<td><input type=button name='buttransfer' value='Transfer' /></td>
</tr>
</table>
<br>
<table align=center width=1160 border=0>
</table>
<table align=center width=950 border=0>
<caption align=right><b
style='font-family: arial; font-size: 13'>Deals on account <b></caption>
<tr bgcolor=navy
style='font-family: arial; font-size: 12; color: white'>
<td border=0 align=left width=150>Deal id</td>
<td border=0 align=left width=100>Deal date</td>
<td border=0 align=left width=100>Start date</td>
<td border=0 align=left width=100>Account</td>
<td border=0 align=left width=100>Deal type</td>
<td border=0 align=right width=100>Amount</td>
<td border=0 align=right width=100>Rate</td>
<td border=0 align=left width=100>Interest</td>
<td border=0 align=right width=100>Maturity date</td>
<!-- <td border=0 align=right width=70>Interdiv</td>
<td border=0 align=right width=70>Amend</td>
<td border=0 align=right width=70>Cancel</td> -->
</tr>
<tr>
<td colspan=9>
<div style='overflow: auto; width: 950; height: 150;'>
<table border=0 width='950'>
<tr bgcolor='#ffffff' height=6>
<td width=150 align=left style='font-family: arial; font-size: 12'></td>
<td width=150 align=left style='font-family: arial; font-size: 12'></td>
<td width=100 align=left style='font-family: arial; font-size: 12'></td>
<td width=100 align=left style='font-family: arial; font-size: 12'></td>
<td width=100 align=left style='font-family: arial; font-size: 12'></td>
<td width=100 align=left style='font-family: arial; font-size: 12'></td>
<td width=100 align=right
style='font-family: arial; font-size: 12'></td>
<td width=100 align=right
style='font-family: arial; font-size: 12'></td>
<td width=100 align=right
style='font-family: arial; font-size: 12'></td>
<td width=100 align=right
style='font-family: arial; font-size: 12'></td>
</tr>
<tr height=6>
<td width=150 />
<td width=100 />
<td width=100 />
<td height=6><input name='InterDiv' type=button size=100
value=' InterDiv ' />
<td><input name='InterDiv' type=button size=100
value=' InterDiv ' disabled /></td>
<td><input name='Amend' type=button size=100
value=' Amend ' />
<td><input name='Amend' type=button size=100
value=' Amend ' DISABLED />
<td><input name='Cancel' type=button size=100
value=' Cancel ' />
<td width=100 />
<td width=100 />
<td width=100 />
</tr>
</table>
</div>
</td>
</tr>
<tr />
<tr />
<!-- <tr>
<td/>
<td/>
<td/>
<td width=100 align=left><input name='deposit' type=button value=' Deposit ' /></td>
<td width=100 align=left><input name='withdrawal' type=button value='Withdrawal' /></td>
<td width=100 align=left><input name='rate_change' type=button value='Rate Change'/></td>
<td/>
<td/>
<td/>
</tr> -->
</table>
</form>
</BODY>
</HTML>
It doesn't mean much - just showing the location
ASKER
currently this work fine in live. The only difference is that I am using Jboss 5 and jdk 1.5.
But deal should be null because of this
<%!
private Deal deal = null;
%>
Because I am setting deal to null
But deal should be null because of this
<%!
private Deal deal = null;
%>
Because I am setting deal to null
>>Because I am setting deal to null
Then you can't call deal.getClients without an NPE
Then you can't call deal.getClients without an NPE
ASKER
but deal is like the object reference to the object Deal. So should I not check for deal.getClients is null ?
ASKER
Question how can this work in a live environment and not in Test(my local machine). Is this related to data maybe.
I am trying to find out all the possible issues ?
I am trying to find out all the possible issues ?
>>but deal is like the object reference to the object Deal. So should I not check for deal.getClients is null ?
You need to check whether 'deal' is null *first*
>>Question how can this work in a live environment and not in Test(my local machine). Is this related to data maybe.
Probably because 'deal' is getting initialized in the live env
You need to check whether 'deal' is null *first*
>>Question how can this work in a live environment and not in Test(my local machine). Is this related to data maybe.
Probably because 'deal' is getting initialized in the live env
ASKER
deal.getClients() is link to
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Deal.java
package deal;
import account.*;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJBObject;
import util.AccountDetails;
import util.TicketDetails;
public interface Deal extends EJBObject {
public abstract String createAccount(String s,
AccountDetails accountdetails, String s1, String s2, String s3,
String s4, String s5, String s6, String s7, String s8, Map map)
throws Exception, RemoteException;
public abstract String interDiv(String s, String s1, String s2, String s3,
String s4, String s5, String s6, String s7, String s8, String s9,
String s10, double d, double d1, String s11, String s12, Map map)
throws NonExistentAccountException, InsufficientBalanceException,
TermAccountException, IOException, Exception, RemoteException;
public abstract String withdrawalTicket(String s, String s1, String s2,
String s3, double d, double d1, String s4, String s5, String s6,
String s7, String s8, String s9, String s10, String s11,
boolean flag, boolean flag1, Map map, int i)
throws NonExistentAccountException, InsufficientBalanceException,
TermAccountException, IOException, Exception, RemoteException;
public abstract String depositTicket(String s, String s1, String s2,
String s3, double d, double d1, String s4, String s5, String s6,
String s7, String s8, String s9, String s10, String s11,
boolean flag, boolean flag1, Map map, int i)
throws NonExistentAccountException, TermAccountException,
ExceededSettlementException, IOException, Exception,
RemoteException;
public abstract String rateChangeTicket(String s, String s1, String s2,
String s3, String s4, double d, Map map)
throws NonExistentAccountException, TermAccountException,
RemoteException;
public abstract String amendTicket(String s, String s1, String s2,
String s3, String s4, String s5, double d, double d1, String s6,
String s7, String s8, String s9, String s10, String s11,
String s12, String s13, boolean flag, boolean flag1, Map map, int i)
throws Exception, RemoteException;
public abstract boolean cancelTicket(String s, String s1, String s2)
throws Exception, RemoteException;
public abstract void createTicket(TicketDetails ticketdetails)
throws RemoteException;
public abstract boolean emailDeal(String s, String s1, String s2, String s3)
throws IOException, Exception, RemoteException;
public abstract boolean setDealFile(String s, String s1)
throws RemoteException;
public abstract ArrayList getClientAccounts(String s)
throws RemoteException;
public abstract ArrayList getAccountsByClient(String s)
throws RemoteException;
public abstract ArrayList getClients()
throws RemoteException;
public abstract ArrayList getSearchClients(String s) throws RemoteException;
public abstract AccountDetails getAccountDetails(String s)
throws RemoteException;
public abstract TicketDetails getTicketDetails(String s)
throws RemoteException;
public abstract ArrayList getDeals(String s) throws RemoteException;
public abstract ArrayList getBankInfo(String s) throws RemoteException;
}
That object needs to be non-null
ASKER
silly question
--->That object needs to be non-null
Is it the Deal object?
--->That object needs to be non-null
Is it the Deal object?
Yes
ASKER
Well that Object is null and also I cannot bug the actual class because it's a interface. I think this is a end of the road?
Yes - it's quite simple. You can't use the methods of an uninitialised object without an exception.
ASKER
So this means I will never be able so slove this issues?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Do you have any guide lines on how to check this?
You should ask the EJB people why Deal would be null when it shouldn't be
Make sure that neither 'deal' nor 'arrClients' is null