tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject URLExistsTag
Date Tue, 25 May 2004 16:33:40 GMT
have done a by-no-means-robust tag that works

import java.io.*;
import java.net.*;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * Output the tag body when a URL resource exists.
 *
 * @author  allistairc
 */
public class URLExistsTag extends TagSupport {

	/** URL */
	private String url;
	
    /** Eval at end of tag */
    public int doStartTag() throws JspException {       
        return doWork();
    }
        
    /**
     * Load the page attributes and attempt to output the specified key
     */
    public int doWork() throws JspException {
        
        try {
        	URL url2 = new URL(url);
        	URLConnection urlConnection = (HttpURLConnection) url2.openConnection();
        	urlConnection.setRequestProperty("method", "head");
        	urlConnection.setDoInput(true);
        	urlConnection.connect();
        	
        	// throws file not found exception when url does not exist
        	BufferedInputStream bis = new BufferedInputStream(urlConnection.getInputStream());
        	
        	return EVAL_BODY_INCLUDE;
        	
        } catch (Exception e) {
        }        	
                
        return SKIP_BODY;
    }
    
    /**
     * Set the URL
     * @param url
     */
    public void setUrl(String url) {
    	this.url = url;
    }
    
    /**
     * Get the URL
     * @return
     */
    public String getUrl() {
    	return this.url;
    }
}





-----Original Message-----
From: Allistair Crossley 
Sent: 25 May 2004 14:52
To: Tag Libraries Users List
Subject: RE: 1.1 / 1.0 Crossover


:)) thanks! It all works perfectly :))

-----Original Message-----
From: Kris Schneider [mailto:kris@dotech.com]
Sent: 25 May 2004 14:41
To: Tag Libraries Users List
Subject: Re: 1.1 / 1.0 Crossover


Remove the TLD files from WEB-INF.

Remove the <taglib> elements from web.xml.

Use a Servlet 2.4 web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
  ...
</web-app>

Use the "well known" URIs in taglib directives:

<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Quoting Allistair Crossley <Allistair.Crossley@QAS.com>:

> Hi Guys
> 
> I have just discovered something odd. My web.xml contains the following:
> 
> 	<taglib>
> 		<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
> 		<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
> 	</taglib>  
> 	
> 	<taglib>
> 		<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
> 		<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
> 	</taglib>  
> 	
> 	<taglib>
> 		<taglib-uri>http://java.sun.com/jsp/jstl/sql</taglib-uri>
> 		<taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
> 	</taglib>  		
> 	
> 	<taglib>
> 		<taglib-uri>http://java.sun.com/jsp/jstl/xml</taglib-uri>
> 		<taglib-location>/WEB-INF/tld/x.tld</taglib-location>
> 	</taglib>  	
> 	
> 	<taglib>
> 		<taglib-uri>http://java.sun.com/jsp/jstl/functions</taglib-uri>
> 		<taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
> 	</taglib>  
> 
> When I run the following JSP
> 
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
> 
> <c:set var="s1" value="There is a castle on a cloud"/>
> <c:out value="${s1}" />
> 
> The value that prints to the screen is
> 
> ${s1}
> 
> When I change to 
> 
> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
> 
> There is a castle on a cloud
> 
> is printed ok.
> 
> I cannot get either of these to work at all...
> 
> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
> <%@ taglib uri="http://java.sun.com/jstl/functions" prefix="fn" %>
> 
> I have all the TLDs and the 2 JARs installed on my webapp.
> 
> I am very confused about what is happening here.
> 
> 
> 
> <FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
> -------------------------------------------------------
> QAS Ltd.
> Developers of QuickAddress Software
> <a href="http://www.qas.com">www.qas.com</a>
> Registered in England: No 2582055
> Registered in Australia: No 082 851 474
> -------------------------------------------------------
> </FONT>

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message