Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

handle nulls on JSP page  RSS feed

 
G Singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi how can I replace "null" from being displayed with an empty string on the JSPs. I don't want to do if(str!=null) checks on every JSP, what would you guys recommend?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you are still using scriptlets and scriptlet expressions in your JSPs. If so, you are about 6 years behind the times.

Use the EL and nulls will simply render as the empty string on your pages.
 
G Singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was seeking help not criticism
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was help. Lower your defensive shields. Your problem is completely solved by the use of modern techniques such as the EL.


 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Essentially, those null checks you're hesitant to sprinkle all over your page is exactly what you're going to need to do if you're just using standard scriptlets.

Obviously, the evolution was to create a custom tag or something that embeds this type of logic, so it's reusable. That evolved into a conglomeration of common practices to be grouped together into standard tag libraries, and eventually, organized frameworks that incorporate all of these tags. And that's how we've evolved into things like JSF and Struts, and the custom tag libraries that are associated with them.

Of course, you don't need to drop a hammer like struts or JSF on your problem. Even just using JSTL tags might be helpful.

-Cameron McKenzie
 
karan wadhwani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or make it empty in bean itself if you are reading from bean,
but best approach is jstl as said above.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!