tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Karnowski" <la...@opennms.org>
Subject Re: <BASE href="...."> ?
Date Tue, 20 Feb 2001 19:55:40 GMT
What I do is define a static utility function somewhere like this:

    /**
     * Return a string that represents the fully qualified URL
     * for our servlet context, suitable for use in the HTML
     * <em>base</em> tag.
     *
     * <p>As an example, suppose your host was www.mycompany.com,
     * you are serving from port 80, and your web application name
     * was "opennms," then this method would return:
     * <code>http://www.mycompany.com:80/opennms/</code></p>
     *
     * @param request the servlet request you are servicing
     */
    public static String calculateUrlBase( HttpServletRequest request ) {
        if( request == null ) {
            throw new IllegalArgumentException( "Cannot take null
parameters." );
        }

        StringBuffer buffer = new StringBuffer();

        buffer.append( request.getScheme() );
        buffer.append( "://" );
        buffer.append( request.getServerName() );
        buffer.append( ":" );
        buffer.append( request.getServerPort() );
        buffer.append( request.getContextPath() );
        buffer.append( "/" );

        return( buffer.toString() );
    }

Then, in my JSP html header, I do this:

  <base HREF="<%=my.project.web.Util.calculateUrlBase( request )%>" />


Not the prettiest solution, especially since you have to add that ugly line
to every JSP, but maybe someone will add a standard JSP action for
calculating this in the future.  I thought about adding a custom taglib for
doing this, but writing a static method was simpler.

Larry Karnowski
larry@opennms.org
http://www.opennms.org/


----- Original Message -----
From: <romain@zzict.nl>
To: <tomcat-user@jakarta.apache.org>
Sent: Tuesday, February 20, 2001 2:00 PM
Subject: <BASE href="...."> ?


> Yo,
> a quick and simple question:
> is there a configuration option that adds a base tag to the jsp pages ?
> if there is, where is it ?
>
> TIA,
>
> Sloot.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
>


Mime
View raw message