[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
Mon Jul 23 10:55:03 CEST 2012


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.










*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


On 23 July 2012 09:26, Enrico Ballarin Dolfin <enrico at sed.ethz.ch> wrote:

> Hi Yves,
>
> On Friday 20 July 2012 21:14:38 Yves Glodt wrote:
> > If you are willing to add another layer, you could implement a tag
> library
> > which transforms the data returned from the WebService into html or
> > something else. I did that with success and used it in many projects. Let
> > me know if you need more information.
>
> could you please give me more information?
>
> Do you have a tag library example or a link to a similar solution?
>
> Many thanks
> Enrico
>
> >
> > On 20 July 2012 11:44, Enrico Ballarin Dolfin <enrico at sed.ethz.ch>
> wrote:
> > > Hi,
> > >
> > > I'm looking for a way to include results of a webservice call into a
> JSP
> > > that
> > > generates an OpenCms 8.0.0 page.
> > >
> > >
> > > The webservice calls can returns a PNG image, a text, an XML file, etc,
> > > that
> > > is stored in a DB table as blob field.
> > >
> > >
> > > For the webservice call I'm using a syntax similar to this:
> > >
> > > /MyServices/GetPngBlob?parameter=...
> > > /MyServices/GetXmlBlob?parameter=...
> > > /MyServices/GetTextBlob?parameter=...
> > >
> > >
> > > While this approach works well for PNG images, e.g.
> > >
> > > <p><img src="/MyServices/GetPngBlob?param2=<%= value %>" /></p>
> > >
> > > I'm having problems to use the GetTextBlob and the GetXmlBlob service:
> > > I need to call the service and to store the result of the service call
> in
> > > a JSP variable (e.g. String data) and then to display it in HTML:
> > >
> > > <p><%= data %></p>
> > >
> > >
> > > The JSP that I use to generate the page has a structure like this and
> > > uses a
> > > bean that I have programmed in Java to be able to access an other DB:
> > >
> > > -------------------------------------------------
> > > <%@page buffer="none" session="false" taglibs="c,cms"
> > >
> > >
> import="java.util.*,org.apache.log4j.*,mypackage.opencms.v8.dbtable.*
> > >     "
> > >
> > > %>
> > >
> > > <%=
> > >
> > >     // create the bean and the other needed objects
> > >     DBTableJspTemplate dbtable = new DBTableJspTemplate(pageContext,
> > >
> > > request,
> > > response);
> > >
> > >     String param1 = request.getParameter("param1");
> > >
> > > ...
> > > ...
> > >
> > > %>
> > >
> > > <cms:formatter var="content" val="value">
> > >
> > > <div class="dbtable">
> > >
> > > ...
> > > ...
> > >
> > > </div>
> > >
> > > </cms:formatter>
> > > -------------------------------------------------
> > >
> > >
> > > Any idea how can I perform the webservice call inside my JSP ?
> > >
> > > Many thanks
> > > Enrico
> > > _______________________________________________
> > > 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
> _______________________________________________
> 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/20120723/caf62dd2/attachment.htm>


More information about the opencms-dev mailing list