You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by lu...@locus.apache.org on 2000/09/11 21:38:43 UTC
cvs commit: jakarta-struts/web/documentation tags.html
luis 00/09/11 12:38:42
Modified: src/conf struts.tld
web/documentation tags.html
Added: src/share/org/apache/struts/taglib BaseTag.java
Log:
Added a <struts:base/> tag destinated to be included in the <head> portion
of a strut application's JSP pages, whenever an acces to resources (images,
stylesheets, javascript files, etc...) is needed via a relative URL.
Revision Changes Path
1.29 +5 -0 jakarta-struts/src/conf/struts.tld
Index: struts.tld
===================================================================
RCS file: /home/cvs/jakarta-struts/src/conf/struts.tld,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- struts.tld 2000/08/30 23:43:23 1.28
+++ struts.tld 2000/09/11 19:38:41 1.29
@@ -1790,6 +1790,11 @@
<tag>
+ <name>base</name>
+ <tagclass>org.apache.struts.taglib.BaseTag</tagclass>
+ </tag>
+
+ <tag>
<name>encodeRedirectURL</name>
<tagclass>org.apache.struts.taglib.EncodeRedirectURLTag</tagclass>
<attribute>
1.1 jakarta-struts/src/share/org/apache/struts/taglib/BaseTag.java
Index: BaseTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/BaseTag.java,v 1.1 2000/09/11 19:38:41 luis Exp $
* $Revision: 1.1 $
* $Date: 2000/09/11 19:38:41 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.util.MessageResources;
public class BaseTag extends TagSupport {
/**
* The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources("org.apache.struts.taglib.LocalStrings");
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
StringBuffer buf = new StringBuffer("<base href=\"");
buf.append(request.getScheme());
buf.append("://");
buf.append(request.getServerName());
buf.append(":");
buf.append(request.getServerPort());
buf.append(request.getContextPath());
buf.append(request.getRequestURI());
buf.append("\">");
JspWriter out = pageContext.getOut();
try {
out.write(buf.toString());
}
catch (IOException e) {
throw new JspException(messages.getMessage("common.io", e.toString()));
}
return EVAL_BODY_INCLUDE;
}
}
1.24 +11 -5 jakarta-struts/web/documentation/tags.html
Index: tags.html
===================================================================
RCS file: /home/cvs/jakarta-struts/web/documentation/tags.html,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- tags.html 2000/08/27 05:21:54 1.23
+++ tags.html 2000/09/11 19:38:41 1.24
@@ -19,7 +19,15 @@
</ul>
-<a name="button"></a>
+<a name="button"></a>
+<h1><i>base</i> - Render A Base Html Tag</h1>
+<p>Renders an HTML <code><base></code> element with an <code>href</code>
+ attribute pointing to the absolute location of the enclosing JSP page. This
+ tag is only valid when nested inside a <code>head</code> tag body. The presence
+ of this tag allows the browser to resolve relative URL's to images, CSS stylesheets
+ and other resources in a manner independent of the URL used to call the ActionServlet.
+ There are no attributes associated with this tag.</p>
+<a href="#Top">Top</a> <a name="cancel"></a>
<h1><i>button</i> - Render A Button Input Field</h1>
<p>Renders an HTML <code><input></code> element of type
@@ -2816,7 +2824,7 @@
<p>Renders an HTML <code><input></code> element of type
<code>text/code>, populated from the specified value or the specified
property of the bean associated with our current <code>form</code>. This
-tag is only valid when nested inside a <code>form</code> tag body.</p>
+tag is only valid when nested inside a <code>form</code> tag body.</code></p>
<table width="100%" border="1">
<tr>
@@ -3153,9 +3161,7 @@
</td>
</tr>
</table>
-
-<a href="#Top">Top</a>
-
+<a href="#Top">Top</a>
</body>
</html>
Re: cvs commit: jakarta-struts/web/documentation tags.html
Posted by Luis Arias <lu...@elysia.com>.
Craig,
Thanks ! :-) I will update the class with your requests... (Sorry for the
comments...)
However, I tested the tag with both a web app mapped to "/" and also when
mapped to "/app" and did not have any problems with a repeated context
path... My test was in the context of a servlet using a RequestDispatcher
to bring up the JSP, but I believe that this also works when calling the JSP
directly.. Are you sure about getRequestURI() including the context path ?
I will be testing this again...
I hadn't seen the method in your utility class... will check it out !
Cheers,
Luis.
----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <st...@jakarta.apache.org>
Sent: Monday, September 11, 2000 9:55 PM
Subject: Re: cvs commit: jakarta-struts/web/documentation tags.html
>
> This will duplicate the context path (which is included in the request
URI. Try changing this line to:
>
> buf.append(request.getServletPath());
> if (request.getPathInfo() != null)
> buf.append(request.getPathInfo();
>
> Or, you could just let the servlet API classes to the reconstruction for
you:
>
> StringBuffer uri =
> HttpUtils.getRequestURL(request);
>
> and manipulate that instead.
>
Re: cvs commit: jakarta-struts/web/documentation tags.html
Posted by Luis Arias <lu...@elysia.com>.
Craig,
Back from checking the spec... You're perfectly right about the context
path (of course :-) ! I must have fumbled with my tests... I'll be taking
care of all of this and checking it ASAP...
Luis.
Re: cvs commit: jakarta-struts/web/documentation tags.html
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Good job Luis! I'd only like to make a couple of suggestions, intermixed below.
luis@locus.apache.org wrote:
> luis 00/09/11 12:38:42
>
> Modified: src/conf struts.tld
> web/documentation tags.html
> Added: src/share/org/apache/struts/taglib BaseTag.java
> Log:
> Added a <struts:base/> tag destinated to be included in the <head> portion
> of a strut application's JSP pages, whenever an acces to resources (images,
> stylesheets, javascript files, etc...) is needed via a relative URL.
>
> Revision Changes Path
> 1.29 +5 -0 jakarta-struts/src/conf/struts.tld
>
> Index: struts.tld
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/src/conf/struts.tld,v
> retrieving revision 1.28
> retrieving revision 1.29
> diff -u -r1.28 -r1.29
> --- struts.tld 2000/08/30 23:43:23 1.28
> +++ struts.tld 2000/09/11 19:38:41 1.29
> @@ -1790,6 +1790,11 @@
>
>
> <tag>
> + <name>base</name>
> + <tagclass>org.apache.struts.taglib.BaseTag</tagclass>
> + </tag>
> +
> + <tag>
> <name>encodeRedirectURL</name>
> <tagclass>org.apache.struts.taglib.EncodeRedirectURLTag</tagclass>
> <attribute>
>
>
>
> 1.1 jakarta-struts/src/share/org/apache/struts/taglib/BaseTag.java
>
> Index: BaseTag.java
> ===================================================================
> /*
> * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/BaseTag.java,v 1.1 2000/09/11 19:38:41 luis Exp $
> * $Revision: 1.1 $
> * $Date: 2000/09/11 19:38:41 $
> *
> * ====================================================================
> *
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 1999 The Apache Software Foundation. All rights
> * reserved.
> *
> * Redistribution and use in source and binary forms, with or without
> * modification, are permitted provided that the following conditions
> * are met:
> *
> * 1. Redistributions of source code must retain the above copyright
> * notice, this list of conditions and the following disclaimer.
> *
> * 2. Redistributions in binary form must reproduce the above copyright
> * notice, this list of conditions and the following disclaimer in
> * the documentation and/or other materials provided with the
> * distribution.
> *
> * 3. The end-user documentation included with the redistribution, if
> * any, must include the following acknowlegement:
> * "This product includes software developed by the
> * Apache Software Foundation (http://www.apache.org/)."
> * Alternately, this acknowlegement may appear in the software itself,
> * if and wherever such third-party acknowlegements normally appear.
> *
> * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
> * Foundation" must not be used to endorse or promote products derived
> * from this software without prior written permission. For written
> * permission, please contact apache@apache.org.
> *
> * 5. Products derived from this software may not be called "Apache"
> * nor may "Apache" appear in their names without prior written
> * permission of the Apache Group.
> *
> * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> * SUCH DAMAGE.
> * ====================================================================
> *
> * This software consists of voluntary contributions made by many
> * individuals on behalf of the Apache Software Foundation. For more
> * information on the Apache Software Foundation, please see
> * <http://www.apache.org/>.
> *
> */
>
> package org.apache.struts.taglib;
>
> import java.io.IOException;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.jsp.JspException;
> import javax.servlet.jsp.JspWriter;
> import javax.servlet.jsp.tagext.TagSupport;
> import org.apache.struts.util.MessageResources;
>
Don't forget a class comment block (with your name in the @author tag).
>
> public class BaseTag extends TagSupport {
>
> /**
> * The message resources for this package.
> */
> protected static MessageResources messages =
> MessageResources.getMessageResources("org.apache.struts.taglib.LocalStrings");
>
I really prefer to see Javadoc comments for significant methods.
>
> public int doStartTag() throws JspException {
> HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
> StringBuffer buf = new StringBuffer("<base href=\"");
> buf.append(request.getScheme());
> buf.append("://");
> buf.append(request.getServerName());
> buf.append(":");
> buf.append(request.getServerPort());
> buf.append(request.getContextPath());
> buf.append(request.getRequestURI());
>
This will duplicate the context path (which is included in the request URI. Try changing this line to:
buf.append(request.getServletPath());
if (request.getPathInfo() != null)
buf.append(request.getPathInfo();
Or, you could just let the servlet API classes to the reconstruction for you:
StringBuffer uri =
HttpUtils.getRequestURL(request);
and manipulate that instead.
> buf.append("\">");
> JspWriter out = pageContext.getOut();
> try {
> out.write(buf.toString());
> }
> catch (IOException e) {
> throw new JspException(messages.getMessage("common.io", e.toString()));
> }
> return EVAL_BODY_INCLUDE;
> }
> }
>
>
> 1.24 +11 -5 jakarta-struts/web/documentation/tags.html
>
> Index: tags.html
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/web/documentation/tags.html,v
> retrieving revision 1.23
> retrieving revision 1.24
> diff -u -r1.23 -r1.24
> --- tags.html 2000/08/27 05:21:54 1.23
> +++ tags.html 2000/09/11 19:38:41 1.24
> @@ -19,7 +19,15 @@
> </ul>
>
>
> -<a name="button"></a>
> +<a name="button"></a>
> +<h1><i>base</i> - Render A Base Html Tag</h1>
> +<p>Renders an HTML <code><base></code> element with an <code>href</code>
> + attribute pointing to the absolute location of the enclosing JSP page. This
> + tag is only valid when nested inside a <code>head</code> tag body. The presence
> + of this tag allows the browser to resolve relative URL's to images, CSS stylesheets
> + and other resources in a manner independent of the URL used to call the ActionServlet.
> + There are no attributes associated with this tag.</p>
> +<a href="#Top">Top</a> <a name="cancel"></a>
> <h1><i>button</i> - Render A Button Input Field</h1>
>
> <p>Renders an HTML <code><input></code> element of type
> @@ -2816,7 +2824,7 @@
> <p>Renders an HTML <code><input></code> element of type
> <code>text/code>, populated from the specified value or the specified
> property of the bean associated with our current <code>form</code>. This
> -tag is only valid when nested inside a <code>form</code> tag body.</p>
> +tag is only valid when nested inside a <code>form</code> tag body.</code></p>
>
> <table width="100%" border="1">
> <tr>
> @@ -3153,9 +3161,7 @@
> </td>
> </tr>
> </table>
> -
> -<a href="#Top">Top</a>
> -
>
> +<a href="#Top">Top</a>
> </body>
> </html>
>
>
>
Craig
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat