java.lang.NumberFormatException: null
java.lang.NumberFormatException: null
I am a beginner in programming and I am currently doing an internship in a company where I have a problem code.
I work on the JCMS Jalios platform. In summary, I have a JSP template that defines a "portlet", and another that defines the "content" of this "portlet". I want to define a variable in the first to retrieve the second.
Here is the code in my first jsp.
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
<% request.setAttribute("nombreCaractereMaximum","80");%>
<%@ include file='doQuery.jsp' %>
<%@ include file='doSort.jsp' %>
<%@ include file='doForeachHeader.jsp' %>
<jsp:include page='<%= "/"+itPub.getTemplatePath(jcmsContext) %>' flush='true'/>
<% request.setAttribute("nombreCaractereMaximum","80");%>
<%@ include file='doQuery.jsp' %>
<%@ include file='doSort.jsp' %>
<%@ include file='doForeachHeader.jsp' %>
<jsp:include page='<%= "/"+itPub.getTemplatePath(jcmsContext) %>' flush='true'/>
And here is the code in the second jsp
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
<% int nombreCaractereMaximum = Integer.parseInt((String)request.getAttribute("nombreCaractereMaximum")); %>
<% int nombreCaractereMaximum = Integer.parseInt((String)request.getAttribute("nombreCaractereMaximum")); %>
but I have this exception : java.lang.NumberFormatException: null
I realize you are saddled with this code written by someone else, but you should be aware for the future that putting Java code into a JSP in this manner has been obsolete for 12 years and is considered a bad practice.
That said, the exception is caused because a null is being passed to the method.
A scoped variables (one created via setAttribute()) created in request scope in one JSP will not be available in any other as the subsequent JSPs execute in new requests.
It's possible that using the session might be an alternative, but the nature of the data isn;t all that clear from what you've posted. What is the nature of the data and why is it being set up as scoped variable in the first place?
here my solution :
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
<%
int nbCars = 200;
request.setAttribute("nombreCaractereMaximum",nbCars);%>
<%
int nbCars = 200;
request.setAttribute("nombreCaractereMaximum",nbCars);%>
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
int nombreCaractereMaximum = 80;
Object tmpNbCars = request.getAttribute("nombreCaractereMaximum");
if (tmpNbCars != null) {
nombreCaractereMaximum = (Integer) tmpNbCars;
}