• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TagLibs

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Respected Sirs,

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

Regards Francis
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I place the tld file anywhere in my application or in a specified directory ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic