0

I use the <jsp:include page="..."> function for a lot of my pages but the one big downfall I keep coming across if that if you put parameters in the page to be included, it seems as though you can't make them optional. Therefore if you have a bunch of usages already of a jsp component and you want to add a parameter to it, you have to find all the places it is included and add the new parameter.

Is there a way to make it so that these parameters are either not required or default to some value if not mentioned in the include statement?

Here's an example:

<div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-8 col-12 offset-sm-2 slider-text">
                            <div class="slider-text-inner text-center">
                                <h1><%=request.getParameter("h1")%></h1>
                                <h2><%=request.getParameter("h2")%></h2>
                            </div>
                        </div>
                    </div>
  </div>



  <jsp:include page="../../Components/smallHero.jsp">
         <jsp:param name="h1" value="Some Text Here"/>
        <jsp:param name="h2" value=""/>
    </jsp:include>
Flypkey
  • 13
  • 1
  • 4

1 Answers1

0

It sounds like the following solves your issue? Its hard for me to believe that headers could be optional though.

request.getParameter("h1") == null ? 'default value' : request.getParameter("h1")

Maybe what you really want is

<c:if test="${not empty param.h1}">
    <h1><c:out value="${param.h1}"/></h1>
</c:if>

The danger to all this is if you don't specify the param in your tag it will take it from the request if it exists.

Deadron
  • 5,135
  • 1
  • 16
  • 27