• Post Reply Bookmark Topic Watch Topic
  • New Topic

using JSP tag lib c:when to compare 2 strings  RSS feed

 
Larry Zheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I need a little help using JSP tag lib c:when to compare 2 strings. Below is the detail.

I have a master jsp file importing a sub jsp, for simplicity sake, I will just call them master.jsp and sub.jsp, respectively.

In master.jsp, I am using



and in sub.jsp, I have




I am expecting that the c:when will do the string comparison, and go into the branch depending on the value I set for param location.

Right now all the comparing are failing, and it goes into ctherwise, and do scenario 3 every time, no matter what param I set (I have tried to print out the location, and loc1, just to make sure the values are correct.

I must have made a stupid mistake in the comparison, and will really appreciate it if someone could help me and point that out.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are mixing the JSTL and EL with Java scriptlets. No can do!

Scripting variables such as loc1 are not visible to the EL.

Why are you using scriptlets 9 years after they have been discredited?
 
Larry Zheng
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You are mixing the JSTL and EL with Java scriptlets. No can do!

Scripting variables such as loc1 are not visible to the EL.

Why are you using scriptlets 9 years after they have been discredited?



Because this is part of a big product I am working, and I don't have a choice what technology should be used here.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoever is choosing the technology should know that scriptlets and JSTL/EL do not mix. Use one or the other (and discredited scriptlets should not be the choice).

You could make it work by promoting the scripting variables to scoped variables, but that's just a big old mess. I'd recommend using just scriptlets over using a mix of incompatible technologies that have to be bound together with duct tape and super-glue.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!