[opencms-dev] How to include results of a webservice call into a JSP that generates an opencms 8.0.0 page?

Enrico Ballarin Dolfin enrico at sed.ethz.ch
Mon Jul 23 15:39:45 CEST 2012


Hi Yves,

On Monday 23 July 2012 08:55:03 Yves Glodt wrote:
> Hi,
> 
> here is some example code. You will also find plenty of tutorials on the
> web. The best is you create a "Dynamic Web Project" in Eclipse and play
> around there.
> 

many thanks for your suggestion. I'm coming forward and I've experimented a 
bit with a separate "Dynamic Web Project" in Eclipse.

Note that I have moved WebContent/META-INF/yourtags.tld to WebContent/WEB-
INF/yourtags.tld to be able to run it, as I have seen in several tutorials.

I could run the example as standalone and I have now the Taglib example 
running as servlet on tomcat, but I cannot access it from inside my opencms 
application:

---------------------
<%@ page session="true" language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>
<%@ taglib prefix="mytags" uri="http://localhost:8080/HelloWorldTag/WEB-
INF/yourtags.tld" %>

<mytags:HelloWorldTag name="John Doe" />
---------------------

Accessing in the browser http://localhost:8080/opencms/opencms/test-tag.jsp 
I'm getting this error:

The absolute uri: http://localhost:8080/HelloWorldTag/WEB-INF/yourtags.tld 
cannot be resolved in either web.xml or the jar files deployed with this 
application.

Do you mean the Taglib has to be run as a separate servlet or do I have to 
integrate it inside my opencms application?

Best regards,
Enrico

> 
> 
> *Save this as WebContent/META-INF/yourtags.tld
> *
> <taglib version="2.0" xmlns="http://java.sun.com/xml/j2ee" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
> 
>     <tlib-version>2.0</tlib-version>
>     <jsp-version>2.0</jsp-version>
>     <short-name>Tag Library</short-name>
>     <uri>http://your.taglib.site.com</uri>
>     <display-name></display-name>
>     <small-icon></small-icon>
>     <large-icon></large-icon>
>     <description></description>
> 
>     <tag>
>         <name>HelloWorldTag</name>
>         <tag-class>com.example.tags.HelloWorldTag</tag-class>
>         <body-content>empty</body-content>
>         <attribute>
>             <name>name</name>
>             <required>false</required>
>             <rtexprvalue>true</rtexprvalue>
>             <description>Your Description</description>
>         </attribute>
>     </tag>
> 
> </taglib>
> 
> 
> 
> *Create this class:
> *
> package com.example.tags;
> 
> import java.io.IOException;
> 
> import javax.servlet.jsp.tagext.TagSupport;
> 
> public class HelloWorldTag extends TagSupport {
> 
>     private static final long    serialVersionUID    = 1L;
>     private String                name                = "";
> 
> 
>     public HelloWorldTag() {
>         super();
>     }
> 
> 
>     public void setName(final String name) {
>         this.name = name;
>     }
> 
> 
>     @Override
>     public int doStartTag() {
>         return EVAL_PAGE;
>     }
> 
> 
>     @Override
>     public int doEndTag() throws javax.servlet.jsp.JspTagException {
>         try {
>             pageContext.getOut().write("<p>Hello " + name + "!</p>");
>         } catch (final IOException e) {
>             e.printStackTrace();
>         }
>         return EVAL_PAGE;
>     }
> }
> 
> 
> 
> *Call the tag from a JSP (which you can place in OpenCms as jsp):
> *
> <%@ page session="true" language="java" contentType="text/html;
> charset=UTF-8" pageEncoding="UTF-8"%>
> <%@ taglib prefix="mytags" uri="http://your.taglib.site.com" %>
> 
> <mytags:HelloWorldTag name="John Doe" />
> 
> 
> 
> Best regards,
> Yves



More information about the opencms-dev mailing list