[opencms-dev] How to use JSP-templates in the same way as HTML with PAGE-type?

Robert Gartman robert_gartman at hotmail.com
Wed Apr 2 20:14:22 CEST 2003


All,

I'm having trouble using JSP templates. My intention is to use all the
features of a PAGE, but instead of having HTML in the file I want to put JSP
content. The expected result is that the JSP page will be accessible in the
same manner as the other PAGes in the navigation.

To accomplish this, I have tried to modify the control file of the PAGE. I
have not been successful though and maybe someone has figured out how to do
this already.

I have created a file of type PAGE and modified the control file to what I
understand should be correct. The following two files are resulting from
this:

\system\modules\my.stuff.com\web_home\login.jsp
==================================================
          <?xml version="1.0" encoding="ISO-8859-1"?>
          <PAGE>
              <class>com.opencms.template.CmsXmlTemplate</class>

<masterTemplate>/system/modules/my.stuff.com/templates/mymastertemplate</mas
terTemplate>
              <ELEMENTDEF name="login">
                  <CLASS>com.opencms.flex.CmsJspTemplate</CLASS>

<TEMPLATE>/system/bodies/system/modules/my.stuff.com/web_home/login.jsp</TEM
PLATE>
              </ELEMENTDEF>
              <ELEMENTDEF name="body">
                  <CLASS>com.opencms.template.CmsXmlTemplate</CLASS>

<TEMPLATE>/system/bodies/system/modules/my.stuff.com/web_home/index.html</TE
MPLATE>
              </ELEMENTDEF>
          </PAGE>
---------------------------------------------------------------------------


\system\bodies\system\modules\my.stuff.com\web_home\login.jsp
==================================================
          <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
          <H1>Output from login.jsp</H1>
---------------------------------------------------------------------------

The file /system/modules/my.stuff.com/templates/mymastertemplate looks like
this:
==================================================
          <?xml version="1.0" encoding="ISO-8859-1"?>

          <xmltemplate>

           <template>
            <element name="jsptemplate"/>
           </template>

           <elementdef name="jsptemplate">
            <class>com.opencms.flex.CmsJspTemplate</class>
            <template>../jsptemplates/mytemplate.jsp</template>
           </elementdef>
          </xmltemplate>
 ---------------------------------------------------------------------------


And finally \system\modules\my.stuff.com\jsptemplates\mytemplate.jsp looks
like:
==================================================
<%@ page session="false" %><%--
--%><%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><%--
--%><cms:template element="head"><%--
--%><!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><cms:property name="title" escapeHtml="true" /></title>

<meta HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=<cms:property
name="content-encoding" default="ISO-8859-1" />">

</head>

</cms:template>
   <body>
  <cms:template element="body">
    <cms:include element="body" />
  </cms:template>


  <cms:template element="login">
    <cms:include element="login" />
  </cms:template>
  </body>
</html>
 ---------------------------------------------------------------------------

When Accessing \system\modules\my.stuff.com\web_home\login.jsp I expected to
see the content of
/system/bodies/system/modules/my.stuff.com/web_home/index.html
followed by the text from
/system/bodies/system/modules/my.stuff.com/web_home/login.jsp

Instead, I see the output from
/system/bodies/system/modules/my.stuff.com/web_home/index.html (meaning the
body) twice. Why? Is there a different (and correct way) to do this or have
I hit a bug?

Thanks for your help
Robert Gartman




More information about the opencms-dev mailing list