Hie... I was wondering whether it is possible to send dynamic content involving "if" or "switch" functions to jsp:param "value" attribute ... one can send a single value which can be represented in the following manner
<jsp:param name="blah" value="<%=blah%>"/>
now what i mean to ask is ..
<jsp:param name="blah" value="<%
if(blah == 1)
out.print("The value is 1");
if(blah == 2)
out.print("The value is 2");
%>"/>
is the above method possible.. when i do the same i get an error stating that an " = " sign is expected after the tag in value attribute ..
I would recommend determining the value of blah prior to executing your jsp. This can be done within a servlet using straight Java. Once you have determined the value of blah place it in the request before forwarding to the jsp.
request.setAttribute("blah", "some value");
Then within your .jsp file you can reference the attribute using jsp expression language.
${blah}
Its best to keep as much logic out of your view (jsp) as possible.
would you consider to change it to
<% if(blah == 1){ %>
<jsp:param name="blah" value="The value is 1"/>
<%}else{%>
<jsp:param name="blah" value="The value is 2"/>
<%}%>
else use equivalent JSTL tags like
<c:choose>
<c:when test="${blan eq 1}">
<jsp:param name="blah" value="The value is 1"/>
</c:when>
<c:otherwise>
<jsp:param name="blah" value="The value is 2"/>
</c:otherwise>
</c:choose>
@gabbi,
You do not necessarily have to have two <jsp:forward>, instead you can declare another variable for holding the value, like below:
<%
String blahValue = "";
if(blah == 1){
blahValue = "The value is 1";
}else if(blah==2){
blahValue = "The value is 2";
}else{
blahValue = "the value is invalid"; }
%>
<jsp:forward>
<jsp:param name="blah" value="<%=blahValue%>"/>
</jsp:forward>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With