using if condition without JSTL

I am using JSTL in my jsp like :
<c:if test="${snippetPreview.showRemaining}">
   <div><a id="more">+${snippetPreview.remainingLines} more lines</a></div>

Open in new window

Controller code corresponding to this JSP :

ModelAndView mav = new ModelAndView("preview");
        mav.addObject("snippetPreview", snippetPreview);

Open in new window :
package org.directi.code.model;

import org.springframework.web.util.HtmlUtils;

public class SnippetPreview {
    private String url;
    private String text;
    private int remainingLines;
    private boolean showRemaining;
    private String mode;
    public static int linesToShow = 7;

    public SnippetPreview(String url, String text, int remainingLines, String mode, boolean showRemaining) {
        this.url = url;
        this.text = text;
        this.remainingLines = remainingLines;
        this.showRemaining = showRemaining;
        this.mode = mode;

    public String getUrl() {
        return url;

    public String getText() {
        return text;

    public int getRemainingLines() {
        return remainingLines;

    public boolean isShowRemaining() {
        return showRemaining;
    public String getMode() {
        return mode;

    public void parseHtml() {
        text = HtmlUtils.htmlEscape(text);


Open in new window

How can i avoid using <c:if> ?
Can it be done with the use of scriptlets or some other approach which does not require the use of
taglibs jstl core

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why use scriptlets when you have jstl? Script lets should be avoided at all costs.
They will litter your code and make it a nightmare to maintain.

If you don't want to use the standard JSTL library (probably due to another question you have posted where you can't get them to work) then maybe create your own custom tag for this particular situation but it seems too overkill to me.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you don't want to use JSTL, then you can use EL. Please copy and paste this demonstration JSP.
   //I am using this scriptlet for a demonstration only.
   //set variables in a scope  
   boolean showRemaining = true; 
   pageContext.setAttribute("showRemaining", showRemaining);
   int remainingLines = 3;
   pageContext.setAttribute("remainingLines", remainingLines);
and here is my solution      
 ${showRemaining?"<div><a id='more'>" += remainingLines += "more lines</a></div>":""}  
 If there are none remaining, then display empty String.
  ${!showRemaining?"<div><a id='more'>" += remainingLines += "more lines</a></div>":""}

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.