• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and String manipulation

 
Mike Landis
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have following code in my JSP. I would like to code it nicer if JSTL
can really do it. I would like to avoid scriplet code if possible.
br
-MP
// selectedOnes is a String that is concatenated

<c:if test="${forwardingEnabled}">
<% selectedOnes = "1"; %>
</c:if>
<c:if test="${ccIncomingEnabled}">
<%
if(selectedOnes.length() == 0)
selectedOnes = "2";
else
selectedOnes += ";2";
%>
</c:if>
<c:if test="${ccOutgoingEnabled}">
<%
if(selectedOnes.length() == 0)
selectedOnes = "3";
else
selectedOnes += ";3";
%>
</c:if>
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:set var="name" scope="scope" value="expression"/> for setting values.
 
Andrea Steelman
Author
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use the JSTL "if" tag and then use the "set" tag as described above. In the expression of the value attribute, you can increment your variable. Although I don't believe you can use the post increment operator, you can use regular addition notation. For example,
I'm using the following code in an application:
<c:set var="requests" scope="application" value="${requests + 1}"/>
Good luck.
 
Mike Landis
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
If tag like:
<c:set var="name" scope="scope" value="expression"/>
is used and variable "name" is string, what kind of string manipulation
operations I can use?
Br
MP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!