1

I've seen JSTL have many functions like

fn:contains()   
fn:containsIgnoreCase() 
fn:endsWith()   
fn:escapeXml()  
fn:indexOf()    
fn:join()   
fn:length() 
fn:replace()    
fn:split()  
fn:startsWith() 
fn:substring()  
fn:substringAfter() 
fn:substringBefore()    
fn:toLowerCase()    
fn:toUpperCase()    
fn:trim()

While in Struts2 we don't have such functionality for UI. So integrating JSTL with Struts2 can utilize these functionalities. But I don't know whether it is a good practice to do so.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    Dave most directly answers this question imo. Further you do have all the above listed functionality trivially available in all struts2 tags. This is because the EL is OGNL which allows you to access all methods of the object in question, so when you are working with a String all methods of String are accessible to you (or for that matter any other type). If you are not working with a String you can of course call toString(). Really you should see what OGNL can do: http://commons.apache.org/proper/commons-ognl/language-guide.html if using Struts2 you should at least know it exists. – Quaternion Jun 03 '13 at 03:00

2 Answers2

3

Yes you can use JSTL with Struts, Spring and any other Java EE-compliant framework. You will find it advantageous to use with (expression language). I highly recommend doing so if you use Java EE.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
  • Sir Is there any drawbacks in doing so..... –  Jun 02 '13 at 04:57
  • There will be no conflicts since JSTL is a straight add-on and the only drawback I can think of is keeping the libraries updated. – Niklas Rosencrantz Jun 02 '13 at 06:59
  • @user2040500 JSTL and EL will work on any Java web application in the view side (e.g. jsp files). Adding a framework like Struts 2 or Spring MVC (not just Spring) just helps you to improve the development of the application (instead of doing it using plain servlets). – Luiggi Mendoza Jun 02 '13 at 13:40
3

There's no reason not to use JSTL in an S2 app, but there may not be any reason to use it, either.

The S2 response wrapper provides JSP EL access to the value stack, so accessing action properties isn't an issue. OGNL can be relatively slow, but it's also far more powerful than JSP EL. Whether or not much of that power belongs in the view layer, however, is debatable, and may influence your decision.

Use whatever taglib provides the functionality you need, recognizing there are tradeoffs whichever direction you go. The bulk of OGNL's security issues have been resolved, AFAIK.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • May be this is not an answer. – Roman C Jun 02 '13 at 19:01
  • @RomanC Of course it is; the question is whether or not it's a good or bad practice, it's neither, and whether or not there are any disadvantages, and there aren't. It was meant more to counter the disinformation in your answer. – Dave Newton Jun 02 '13 at 19:19
  • What disinformation are you talking? All information from the Apache and SpringSource sites. Everything else is IMHO I have practiced myself. – Roman C Jun 02 '13 at 21:40
  • @RomanC the part where you say it is bad practice to use JSTL in struts 2. Show me the link where is says not to use JSTL, I will edit it out. – Dave Newton Jun 02 '13 at 22:25
  • Aha, got you, you say there's not a bad practice, but also there's not a good practice. I'd say not a good practice, rather than not a bad practice instead of saying a bad practice. How do you think it would be better? – Roman C Jun 02 '13 at 22:46
  • @RomanC JSTL is a known quantity with widely-understood functionality, and they're almost always faster than the S2 tags. I also worry about OGNL whizzes trying to put too much functionality into the view layer, which OGNL makes it easy to do. Until OGNL is more performant (likely to happen) and better-known (not likely) it's not always the best choice. That said, I use it heavily, because I know it, and like it :-) – Dave Newton Jun 02 '13 at 23:09
  • That's what I do why should I say JSTL is a good practice if using it I don't like it and can't do things that I can do with OGNL. I throw it away, saying it is not a good practice, I don't like JSTL and don't like if you show me your JSTL code. – Roman C Jun 02 '13 at 23:20
  • @RomanC The question asked if there were any disadvantages to using JSTL or if it was a good/bad practice. There's nothing wrong with using JSTL with S2, there are reasons to use it, there are reasons not to. I explained as much to the OP in response to the question-that's all. That I like OGNL isn't a sufficient reason to call JSTL a bad practice. – Dave Newton Jun 03 '13 at 01:04