• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JSP and String manipulation

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:set var="name" scope="scope" value="expression"/> for setting values.
 
Author
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic