• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TagLibs

 
francis varkey
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respected Sirs,

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

Regards Francis
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I place the tld file anywhere in my application or in a specified directory ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic