0

Is it good to use scriptlets in jsp files? I'm using them in one of my project but it have been so frustrating using them. Especially simple if statements, whenever I add if statement and do comparison by using attributes that are set properly it will give me NullPointerException error.

Is using scriptlets in jsp files good or bad programming practise?

Amir
  • 1,031
  • 2
  • 19
  • 42
  • if you are getting NPEs you're either doing something wrong setting the attributes or you're not properly checking whether something is null that can be null. You're not getting NPEs because of some evilness in the JSP system – jwenting Jun 05 '13 at 11:45
  • @jwenting Tags deal with nulls more gracefully under some circumstances. – Dave Newton Jun 05 '13 at 11:53
  • @DaveNewton true, because they have been programmed to do so. I'm not endorsing scriptlets, but providing feedback on his implicit claim that his code fails because it is a scriptlet, which is wrong. It'd fail if passed the same arguments if it were inside a Java class as well. – jwenting Jun 05 '13 at 12:03

1 Answers1

0

It is not recommonded. Try to use JSTL tags rather than using scriptlet

import <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

when you are going to use JSTL tags

PSR
  • 39,804
  • 41
  • 111
  • 151
  • Thanks, I think I will change all those scriptlets to JSTL. JSTL's have been working very well this far :). – Amir Jun 05 '13 at 11:36
  • Okay I just started using JSTL and I solved a problem in one minute that took me many hours to do it with scriptlets. I highly recommend avoid using scriptlets and use JSTL's instead. – Amir Jun 05 '13 at 11:47
  • Of course, it was solved :). Thank you very much. – Amir Jun 05 '13 at 11:55