• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

handle nulls on JSP page

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was seeking help not criticism
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic