On Wed, 13 Jun 2001, Rick Horowitz wrote:

> Hi,
> 
> I'm trying to use href links with Struts templates, and can't figure out 
> how to make my href links work properly.  [Templates seem to work just 
> fine, otherwise.]... my compliments.
> 
> 1. I want to use Struts <html:link> tags so that to automatically do URL 
> session encoding.
> 

Struts does this automatically for you.

> 2. I want to use absolute URLs to make coding of urls more robust. For 
> example, if I have a directory structure of JSPs:
>          jsp
>          jsp/prodinfo
>          jsp/faq
>       ...I want to be able to code the url something like... 
> jsp/faq/faq1.jsp or jsp/prodinfo/info1.jsp, in case I change the directory 
> structure, rather than using relative links, e.g. ../faq/faq1.jsp.
> 

I have found it best to use context-relative URLs starting with a
"/" character throughout my applications, rather than trying to use
relative links -- for the reasons that you are probably familiar with.  To
do that for links, use the "page" attribute to specify the destination --
Struts will prepend the context path of the current application for you,
so that the browser always goes the right place.  For example, you might
code:

    <html:link page="/jsp/faq/faq1.jsp">To the FAQ</html:link>

> 3. For the portion of the website that I'm currently working on, I am 
> creating href links from one JSP to other JSPs.  [For other portions of the 
> website, I will be using an MVC architecture, hence forwarding from a 
> servlet to a JSP and vice versa.]
> 

It works either way, but remember that links directly from one page to
another bypasses the controller -- and therefore bypasses the stuff that
the controller servlet does for you.


> 4. I have tried various approaches to using the <html:base/> tag in the 
> HTML <HEAD> section of my Struts template file, not using a base tag, and 
> have tried using the following to set the html base:
>          <BASE HREF="<%= "http://";
>                  +request.getServerName() +":"
>                  +request.getServerPort()
>                  +request.getContextPath() %>/" >
>       Although the latter works with regular <a href > tags, it does not 
> seem to work with <html:link> Struts tags.
> 

See the <html:base/> tag for a way to do this automatically.

However, whether you create it yourself or not, the <base> element affects
only relative hyperlinks.  If you follow my suggestion above (always use
context-relative links), you won't need it.

> I have tried a variety of combinations of these base tags with a variety of 
> combinations of url encodings, but cannot seem to get them to work -- 
> except with regular <a href> tags using the
>          <BASE HREF="<%= "http://";
>                  +request.getServerName() +":"
>                  +request.getServerPort()
>                  +request.getContextPath() %>/" >
>          base tag setting.
> 
> Thank you in advance to anyone who can help,
> 
> --------------------
> Rick Horowitz
> 
> 

Craig


Reply via email to