• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL - If the URL is equal any of these three strings

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to find a way that if the current URL is equal any of the three strings some files should be loaded or not.
To do this I wrote this:



But I don't know how to check the URL with all three strings.

Could you please help me?

Thanks

">
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not the best way to be doing this.

Firstly, I'd handle this in the controller servlet for the JSP. If you don't have one, you should. Please read this article for details.

Then, I would not check for protocol and domain in the string. What if it's using https? What if you move the app to a new domain? You should not have to change code when these occur. So just check the path part of the URL, not the whole URL.

Then, I'd set a variable (an enum might be nice with values like; BASE, MENS, WOMENS, and send that to the JSP.

JSP Rule of Thumb #1: make the JSP as stupid as possible. Do all the heavy work in the servlet controller.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Bear said. There's a very good reason that Model/View/Controller (MVC) is the prevailing architecture for GUI applications, both web-based and otherwise. It's a LOT easier to maintain an application where the logic and the view are in separate components. It's also a lot easier to port such apps, and you also gain a lot of useful power. For example, one Model can be displayed in multiple views, such as a spreadsheet with matching chart. And conversely, a composite view can source from multiple models.

Also, when you have logic on both View and Model that interacts, it becomes a "treasure hunt" every time you need to find which file something is done in and changes to one object often breaks stuff in the other.

Then there's the practical fact that it's a   son of a   to debug logic on a View Template, such as a JSP. It's punitively difficult to set breakpoints and view/modify data for code in a JSP. Much better to put that stuff in a service class and use the normal debugger features.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic