[opencms-dev] How to include results of a webservice call into a JSP that generates an opencms 8.0.0 page?
Yves Glodt
yg at mind.lu
Tue Jul 24 08:29:05 CEST 2012
Hi Enrico,
On 23 July 2012 15:39, Enrico Ballarin Dolfin <enrico at sed.ethz.ch> wrote:
> 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.
>
>
ok
> 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<http://localhost:8080/HelloWorldTag/WEB-%0AINF/yourtags.tld>"
> %>
>
Try to change the uri to "/WEB- INF/yourtags.tld". That should help I hope
:-)
Also, I forgot to mention that you need to build a jar from your eclipse
project and deploy it to WEB-INF/lib of your OpenCms installation.
Here is a build-file for ant which I use for this purpose:
<?xml version="1.0" encoding="UTF-8"?>
<project default="buildTaglib" basedir="." name="taglib">
<!--
http://ant.apache.org/manual/CoreTasks/jar.html
http://ant.apache.org/manual/tutorial-tasks-filesets-properties.html
http://snippets.dzone.com/posts/show/1600
http://ant.apache.org/manual/dirtasks.html#directorybasedtasks
http://onlamp.com/pub/a/php/2005/12/20/php_ant.html?page=1
-->
<target name="init">
<property name="temp.dir" value="${java.io.tmpdir}/${user.name}/${
ant.project.name}" />
<mkdir dir="${temp.dir}" />
<property name="lib.dir" value="WebContent/WEB-INF/lib" />
<property name="src.dir" value="$[basedir}/src" />
<property name="build.dir" value="${basedir}/ant-build" />
<property name="tld.file" location="./WebContent/META-INF/yourtags.tld"
/>
</target>
<target name="compile">
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${basedir}/build-libs" includes="**/*.jar" />
</path>
<javac srcdir="./src" classpathref="classpath" target="1.6"
source="1.6" destdir="${temp.dir}"
debug="on"
debuglevel="lines,source"
/>
</target>
<target name="jar">
<delete file="hello.jar" />
<property name="version.num" value="1.00" />
<buildnumber file="build.num" />
<tstamp>
<format property="buildTimeStamp" pattern="yyyyMMdd-HHmmss"
timezone="Europe/Luxembourg" />
</tstamp>
<mkdir dir="${temp.dir}/META-INF" />
<copy file="./WebContent/META-INF/yourtags.tld"
todir="${temp.dir}/META-INF" />
<manifest file="MANIFEST.MF">
<attribute name="Built-By" value="${user.name}" />
<attribute name="Implementation-Version"
value="${version.num}-b${build.number}" />
<attribute name="Built-Date" value="${buildTimeStamp}" />
</manifest>
<jar destfile="taglib-${buildTimeStamp}.jar" basedir="${temp.dir}"
includes="**/*" manifest="MANIFEST.MF" compress="yes" />
</target>
<target name="cleanup">
<delete dir="${temp.dir}" />
</target>
<target name="buildTaglib" depends="init,compile,jar,cleanup" />
</project>
> <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
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20120724/c0b59196/attachment.htm>
More information about the opencms-dev
mailing list