Pessoal, estou tentando criar uma taglib personalizada para alguns serviços. Porem nao consegui criar nem o basico. Criei uma taglib(ou tentei) para mostrar a hora atual do sistema. Sendo assim, criei a classe TagHoraAtual.java que tem o seguinte codigo abaixo:
package myTags;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class HoraAtualTag extends TagSupport {
private static final long serialVersionUID = 1L;
public HoraAtualTag() {
super();
}
/**
* doStartTag
*
* @see javax.servlet.jsp.tagext.Tag#doStartTag()
*/
public int doStartTag() throws JspException {
try {
String formatoLong = "EEEEEE',' dd 'de' MMMM 'de' yyyy";
SimpleDateFormat formatter = new SimpleDateFormat(formatoLong);
String horaAtual = formatter.format(Calendar.getInstance().getTime());
pageContext.getOut().print(horaAtual);
} catch (IOException e) {
throw new JspException(e.getMessage());
}
return SKIP_BODY;
}
}
Criei o arquivo descritor myTags.tld
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
" http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<!-- INICIO Tag Lib -->
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>2.0</jspversion>
<shortname>MyTags</shortname>
<info>My tag's</info>
<tag>
<name>horaAtual</name>
<tagclass>myTags.HoraAtualTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Mostra a hora atual do sistema em formato longo</info>
</tag>
</taglib>
<!-- FIM Tag Lib -->
Alterei o web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" 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
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description>
Minhas tags
</description>
<!--
Esse codigo seta como pagina princial o TagTester.jsp
<welcome-file-list>
<welcome-file>TagTester.jsp</welcome-file>
</welcome-file-list>
-->
<!--
Entrada é: http://localhost:8080/HUR/TagTester.jsp
Porem quero mudar para: http://localhost:8080/HUR/home
para isso tenho que utilizar o servlet e o servlet-mapping
orientação extraida do livro JavaServe Pages Guia do Desenvolvedor pag: 87
-->
<servlet>
<servlet-name>IndexPage</servlet-name>
<jsp-file>/TagTester.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>IndexPage</servlet-name>
<url-pattern>/home</url-pattern>
</servlet-mapping>
<!-- INICIO Configurações JSP -->
<jsp-config>
<taglib>
<taglib-uri>/my_tags</taglib-uri>
<taglib-location>/WEB-INF/myTags.tld</taglib-location>
</taglib>
</jsp-config>
<!-- FIM Configurações JSP -->
</web-app>
E por fim, coloquei ele no JSP: TagTester.jsp
<%@ taglib uri="http://localhost:8080/HUR/home/my_tags" prefix="mt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'TagTester.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. E são: <mt:horaAtual/> <br>
</body>
</html>
Porem, na hora de startar o tomcat e abrir esse projeto, ele diz assim:
org.apache.jasper.JasperException: This absolute uri (http://localhost:8080/HUR/home/my_tags) cannot be resolved in either web.xml or the jar files deployed with this application
Por favor me ajudem, o que poderia ser feito para consertar isso? estaria alguma coisa errada nessa configuração?