wood burning stoves 2.0*
The moose likes JSP and the fly likes TagLibs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "TagLibs" Watch "TagLibs" New topic
Author

TagLibs

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Respected Sirs,

I am trying to demonstrate the use of taglibs.

I wrote the following three files.
In which locations these files placed.Please check
these files and verify. And please
tell how to configure the 'web.xml' file.

sslCheck.java
***************8
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.TagSupport;

public class sslCheck extends TagSupport {

private String errorpage=null;

public void setErrorpage(String errorpage) {
this.errorpage=errorpage;
}

public int doStartTag() throws JspException {
try {
HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
HttpServletResponse response=(HttpServletResponse)pageContext.getResponse();
if(request.getScheme().indexOf("https")==-1) {
if(errorpage!=null) {
// redirect to the error page
response.sendRedirect(errorpage);
} else {
// redirect to the page using ssl
String jumpURL="https://"+request.getServerName()+request.getRequestURI();
if(request.getQueryString()!=null) jumpURL+="?"+request.getQueryString();
response.sendRedirect(jumpURL);
}
return SKIP_PAGE;
}
} catch (IOException ioe) {
throw new JspTagException("sslcheck tag failed");
}
return EVAL_BODY_INCLUDE;
}

public int doEndTag() {
return EVAL_PAGE;
}
}
*******************************************


sslcheck.tld
***********
<?xml version="1.0" encoding="UTF-8"?>
<taglib>
<tlibversion>1.0</tlibversion>
<shortname>sslchk</shortname>
<info>Tag library for checking SSL</info>
<tag>
<name>sslcheck</name>
<tagclass>sslCheck</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>errorpage</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

************************************

ssl.jsp
*********

<%@ taglib prefix="sslchk" uri="/WEB-INF/jsp2/sslCheck.tld" %>
<sslchk:sslcheck/>

*******************************************************


if possible please tell the execution procedure breifly.


Thanks in advance

Regards Francis
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Off the bat, I'd suggest you follow established practices such as naming classes with a capital letter (SslCheck rather than sslCheck) and place all classes in a package other than the default.

Also, assign a URI to your tag library within the tld file and use that URI to reference the tag library from the taglib directive.

There is no need for any web.xml entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Respected Sirs,

what is uri atribute in taglib.please explain with simple examples.

Regards Francis
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

The URI is an identifier string that is unique to the taglib. It is assigned within the tld file, and then is referenced by the taglib directive in a JSP.

Look at the TLD files for the JSTL for some good examples.
francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Can I place the tld file anywhere in my application or in a specified directory ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Anywhere in the WEB-INF hierarchy if a standalone file. If it's already in a jar file, no need to extract it, the container will find it in the jar,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: TagLibs
 
Similar Threads
Problem while Tag lib Up gradation
Can't deploy code for taglibs on Tomcat 5.5
Custom Tags - Repeating Tags
Jsp Custom Tag
XML parsing error on file /WEB-INF/tlds/diagnostics.tld