• 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

Tags Not Scriplet

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone plz tell me how do I write the following scriplet code using tags (either struts or JSTL)

[% if(request.getServerPort() == 8443) {%]

[base href="https://<%=request.getServerName()+ ":" + request.getServerPort() + request.getContextPath() %>/" /]
[%}

else { %]
[base href="http://<%=request.getServerName()+ ":" + request.getServerPort() + request.getContextPath() %>/" /]
[%} %]

where every square bracket is actually an angle bracket.

thanks
Imad
 
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
Here's how I might do it:



Actually, I'd probably write a custom tag to get all the goo of the page, but this is probably pretty close to how I'd do without writing my own tag.

I might probably also factor out pageContext.request to its own scoped variable since it is referenced so many times.
[ September 16, 2005: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh, you forgot to look at the superclass ServletRequest and it's getScheme method which eliminates the need for the switch.
It will also allow you to configure the server's ports without having to alter your code.



Also, getContextPath will provide the preceeding forward slash so you don't want to put it between getServerName and getContextPath

I agree with Bear though, it's much too long; begs for a custom tag.
[ September 16, 2005: Message edited by: Ben Souther ]
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much. I'll use Ben's solution
Thanks
 
Bear Bibeault
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

Thank you so much. I'll use Ben's solution



Good plan. The less goo on the page the better. I just hope that my example was instructive with regards to using JSTL/EL on page for other purposes.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben

I am trying to use the solution you provided but its not working in IE 6. It works fine in Mozilla. Do you know why ?

Appreciate your help.
Thanks
Imad
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your feedback Bear. Your example was no doubt helpful.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is server side code, it shouldn't make any difference what browser you're using. Look at the HTML source and see if it's being printed any differently.

If you mean that the <BASE tag isn't working as you expected, that's a different issue and has nothing to do with JSP.

The more common approach for J2EE apps is to make all links relative to the context root:
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic