The usage of scriptlets is always discouraged. Instead one should use tag libs like JSTL or Expression Language (EL).
The question always arises that why should we not use scriptlets in JSP when the same task can be performed using scriptlets as well.
Here is why one should avoid using scriplets in JSPs:
- JSP Scriptlets reduces the maintainability and readibility of the code and hence making it difficult to read and make further changes.
- JSP Scriptlets can not be re-used.
- JSP Scriptlets are not unit-testable.
- JSP Scriplets merge the presentation with business logic which is highly prone to errors.
- Last but not least, if JSP Scriptlets throws an exception, it breaks the whole page there and doesn’t move further in the processing.