• Post Reply Bookmark Topic Watch Topic
  • New Topic

request.setAttribute => java.lang.NumberFormatException: null  RSS feed

 
Paul Jango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people,

first of all sorry for my bad English but I'm French and not gifted in language.

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.



And here is the code in the second jsp



but I have this exception : java.lang.NumberFormatException: null


Thanks you for your help :) !


Paul.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

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?
 
Paul Jango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply :)

Yes the project was started by the previous student.

I'll try to be more clear about the nature of the data. I have a website where there are articles. Depending on the page on which one finds oneself, the same articles are displayed differently. In a page, the items are displayed as: title, an image and a preview of the article.

In the first case, the preview must be 80 characters. So the student before me had put:
<jalios:wiki truncateLength='80'>


But I've added a new event view should be 200 characters. I just wanted to copy / paste the code and just change the value 80 by 200, but it would have made two template "portlet" and 2 template "content." But the chief told me that it was all too much for just copy and paste a value and only wants two template "portlet" with an attribute that sets and only one template "content." What I tried to do ...


at left : what I wanted to do

at right :what I must do and I try to do.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why are you trying to pass the character limit around? If it's a preset limit, just make it a context parameter in the deployment descriptor and read it from the servlet context.

If you were using the modern JSTL and EL as opposed to Java scriptlets (so someone used this in modern code? :shock: ) the initParam builtin variable gives easy access to such values.

In scriptlets, you'll need to call the appropriate method on the servlet context instance.
 
Paul Jango
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry not to have responded to the previous message, but I finally figured out how to run my code. I know you told me it was not the best way to do it, but I was asked to do it like that :)

Thank you very much for paying attention to my problem. and thank you for having responded and helped me.

Regards

Paul

here my solution :






 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!