[opencms-dev] How to access own Java Class via JSP in OpenCMS 5 RC2

Alexander Kandzior alex at opencms.org
Sun Apr 6 16:10:02 CEST 2003


Ralf,

for OpenCms managed JSP pages, go to the "Administration" view and open
"Flex Cache Administration". Click on "Purge JSP". This cleans the
OpenCms JSP cache, which in turn should cause Tomcat to update all JSP
generated Servlets. Alternativly, if you are logged in as member of the
Administrator group, append a "&_flex=purge" parameter to any JSP you
request. If this does not work, check the clock settings on your OpenCms
server.

Best Regards,
Alex.

Alexander Kandzior
Alkacon Software - The OpenCms Experts
http://www.alkacon.com

> -----Original Message-----
> From: opencms-dev-admin at opencms.org 
> [mailto:opencms-dev-admin at opencms.org] On Behalf Of ambiesense at gmx.de
> Sent: Sunday, April 06, 2003 3:53 PM
> To: opencms-dev at opencms.org
> Subject: RE: [opencms-dev] How to access own Java Class via 
> JSP in OpenCMS 5 RC2
> 
> 
> Hello Alex,
> 
> you are right. The cmsObject is not null. I have faced a kind 
> of cache problem. Tomcat is caching JSP (use the Servlets 
> even though you have exchanged the JSP files). Sometimes I 
> have exchanged the JSP files in OpenCMS (but used the same 
> name) and the output was from the old JSP (since Tomcat used 
> the old generated Servlets for that)... Tricky!
> 
> Do you know how I am able to avoid such things? Can I 
> configure Tomcat that it should always compile i.e. for every 
> access or every session or every time Tomcat get restarted? 
> Is there another way to influence OpenCMS in a way that it 
> does not cache and create strange system behaviour?
> 
> In the meantime I look for the real problem which is, as you 
> have expected correctly, in my bean.
> 
> Cheers
> Ralf
> 
> 
> > Ralf,
> > 
> > your code should work. Try inserting a check if the 
> CmsObject is null 
> > bevore you insert it into your bean, it shouldn't be. Maybe it's an 
> > error in your bean, post the code of your bean in case you 
> need more 
> > help.
> > 
> > Best Regards,
> > Alex.
> > 
> > Alexander Kandzior
> > Alkacon Software - The OpenCms Experts
> > http://www.alkacon.com
> > 
> > > -----Original Message-----
> > > From: opencms-dev-admin at opencms.org
> > > [mailto:opencms-dev-admin at opencms.org] On Behalf Of 
> ambiesense at gmx.de
> > > Sent: Saturday, April 05, 2003 12:52 PM
> > > To: opencms-dev at opencms.org
> > > Subject: RE: [opencms-dev] How to access own Java Class via 
> > > JSP in OpenCMS 5 RC2
> > > 
> > > 
> > > Hi,
> > > 
> > > I send this email the THIRD time, since I think there was a
> > > technical problem (have not received it). Sorry for possible 
> > > higher traffic... :-?
> > > 
> > > I tried another approach (see JSP below). Unfortunately
> > > cmsObject is null. Does somebody knows why? The code used 
> > > should work like the useBean setProperty appraoch - right?
> > > 
> > > 
> > > <html>
> > >   <head>
> > >     <title>Test</title>
> > >   </head>
> > >   <body>
> > >     <h2>
> > >       Test <BR><BR>
> > >     
> > >     <%    
> > >       // initialise Cms Action Element
> > >       com.opencms.flex.jsp.CmsJspActionElement cms = new
> > >       
> com.opencms.flex.jsp.CmsJspActionElement(pageContext, request,
> > >       response);
> > >     
> > >       // collect the CmsObject required to access the OpenCms VFS
> > >       com.opencms.file.CmsObject cmsObject = cms.getCmsObject();
> > > 
> > >       mypackage.MyBean myBean = new mypackage.MyBean();
> > >       myBean.setCmsObject(cmsObject);
> > >       myBean.dosomething();
> > >     %>
> > >     
> > >     </h2>
> > > </body>
> > > </html>
> > > 
> > > 
> > > 
> > > Cheers,
> > > Ralf
> > > 
> > > 
> > > > Just some quick things on that from my side:
> > > > 
> > > > Get an instance from the CmsObject like this on your JSP page:
> > > > 
> > > > <%
> > > >  
> > > > // initialise Cms Action Element
> > > > com.opencms.flex.jsp.CmsJspActionElement cms = new 
> > > > com.opencms.flex.jsp.CmsJspActionElement(pageContext, request,
> > > > response);
> > > >     
> > > > // collect the CmsObject required to access the OpenCms VFS 
> > > > com.opencms.file.CmsObject cmsObject = cms.getCmsObject();
> > > > 
> > > > %>
> > > > 
> > > > Now create an instance of your Bean. Your Bean should 
> then have a
> > > > method like "setCmsObject(CmsObject cms)". Use this method 
> > > to pass the
> > > > OpenCms object to the bean. Do stuff with the CmsObject in
> > > your bean.
> > > > 
> > > > I do not recommend storing the CmsObject in the 
> session. Reason is
> > > > that that CmsObject also contains the credentials of the 
> > > user who has
> > > > logged on to OpenCms (user is Guest if he is not logged
> > > on). This also
> > > > means that you will have only accesss to resources that
> > > user Guest can
> > > > access. Make sure your permissions are set accordingly. Storing 
> > > > the
> > > > OpenCms object in the context is o.k. as long as it is 
> the page or 
> > > > request context.
> > > > 
> > > > Best Regards,
> > > > Alex.
> > > > 
> > > > Alexander Kandzior
> > > > Alkacon Software - The OpenCms Experts http://www.alkacon.com
> > > > 
> > > > > -----Original Message-----
> > > > > From: owner-opencms-dev at www.opencms.org 
> > > > > [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of
> > > Marcus Redeker
> > > > > Sent: Friday, April 04, 2003 12:30 AM
> > > > > To: opencms-dev at www.opencms.org
> > > > > Subject: RE: [opencms-dev] How to access own Java Class via
> > > > > JSP in OpenCMS 5 RC2
> > > > > 
> > > > > 
> > > > > You can get access to the CmsObject from your JSP request 
> > > > > object. Look into the nav-demo.jsp Once you have the 
> CmsObject 
> > > > > you can give it into your bean class using a normal 
> setter. It 
> > > > > should also be possible to store the CmsObject within the 
> > > > > Web-Session or even the Context. But I am not sure 
> about that. 
> > > > > Maybe Alexander knows about that.
> > > > > 
> > > > > Cheers,
> > > > > --Marcus
> > > > > 
> > > > > 
> > > > > 
> > > > > > -----Original Message-----
> > > > > > From: opencms-dev-owner at www.opencms.org
> > > > > > [mailto:opencms-dev-owner at www.opencms.org] On Behalf Of 
> > > > > > ambiesense at gmx.de
> > > > > > Sent: Thursday, April 03, 2003 8:08 PM
> > > > > > To: opencms-dev at www.opencms.org
> > > > > > Subject: RE: [opencms-dev] How to access own Java Class via
> > > > > > JSP in OpenCMS 5 RC2
> > > > > > 
> > > > > > 
> > > > > > Hello,
> > > > > > 
> > > > > > thanks for your quick answer :) This sounds good. I 
> have had a
> > > > > > look to the usebean Tag. However this bean need to get 
> > > access to
> > > > > > the OpenCMS instance. This seems to be a problem. I
> > > have used that
> > > > > > code before triggered by a content template. Every time
> > > a website,
> > > > > > made from this OpenCMS content template, was accessed. My 
> > > > > > class
> > > > > > overwrites that method:
> > > > > > 
> > > > > > public byte[] getContent(CmsObject cms, String templateFile,
> > > > > > String elementName,
> > > > > >                              Hashtable parameters, String
> > > > > > templateSelector) throws CmsException {
> > > > > > 
> > > > > > so I got access to CmsObject. With this CmsObject I
> > > could access
> > > > > > i.e. Files in the VFS or users in OpenCMS.
> > > > > > 
> > > > > > How can I do this with the JSP approach?
> > > > > > 
> > > > > > Any help would be highly appreciated!
> > > > > > 
> > > > > > Cheers,
> > > > > > Ralf
> > > > > > 
> > > > > > > Hi,
> > > > > > > 
> > > > > > > this is no problem. You just have to make sure that the
> > > > > > OpenCMS webapp
> > > > > > > is seeing your class. Either put it into the  
> opencms.jar or
> > > > > > > under WEB-INF/classes. If you just want to use 
> the class as a
> > > > > > bean you can
> > > > > > > use the "useBean" - Tag. For that you don't need to
> > > write your
> > > > > > > own tags.
> > > > > > > 
> > > > > > > --Marcus
> > > > > > > 
> > > > > > > > -----Original Message-----
> > > > > > > > From: opencms-dev-owner at www.opencms.org 
> > > > > > > > [mailto:opencms-dev-owner at www.opencms.org] On Behalf Of 
> > > > > > > > ambiesense at gmx.de
> > > > > > > > Sent: Thursday, April 03, 2003 6:23 PM
> > > > > > > > To: opencms-dev at www.opencms.org
> > > > > > > > Subject: [opencms-dev] How to access own Java Class via 
> > > > > > > > JSP in OpenCMS 5 RC2
> > > > > > > > 
> > > > > > > > 
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > I followed the advice of Tim Howland and want to use
> > > > > JSP and JSTL
> > > > > > > > for dynamic page generation. I am planning to
> > > develop an Hello
> > > > > > > > World example:
> > > > > > > > 
> > > > > > > > I want to have a JSP page with a very basic form 
> > > > > > > > (textfield
> > > > > > > > and
> > > > > > > > submit button).  The user enters his name  in the 
> > > > > textfield (i.e.
> > > > > > > > Bob) and press the submit button. The word get somehow
> > > > > transported
> > > > > > > > to another JSP page which calles a method in my own
> > > Java class
> > > > > > > > with the word as parameter. The Java class simply
> > > returns the
> > > > > > > > input (Echo method). This result should be displayed in
> > > > > this JSP
> > > > > > > > so it finally produces the output: "Hello World Bob".
> > > > > > > > 
> > > > > > > > Is this generally possible? Will I need to develop my
> > > > > own TLD file
> > > > > > > > declaring the tags I want to be able to use? Does
> > > somebody has
> > > > > > > > already developed some JSP which access a own
> > > > > > > > (non-OpenCMS) Java class (i.e. a Java Bean) ?
> > > > > > > > 
> > > > > > > > Thanks in advance,
> > > > > > > > Ralf
> > > > > > > > 
> > > > > > > > --
> > > > > > > > +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> > > > > > > > Bitte lächeln! Fotogalerie online mit GMX ohne eigene
> > > > > > > > Homepage!
> > > > > > > > 
> > > > > > > > 
> > > > > > > 
> > > > > > > 
> > > > > > 
> > > > > > --
> > > > > > +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> > > > > > Bitte lächeln! Fotogalerie online mit GMX ohne eigene
> > Homepage!
> > > > > > 
> > > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > 
> > > 
> > > --
> > > +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> > > Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
> > > 
> > > _______________________________________________
> > > This mail is send to you from the opencms-dev mailing 
> list To change 
> > > your list options, or to unsubscribe from the list, please visit 
> > > http://mail.opencms.org/mailman/listinfo/opencms-dev
> > > 
> > > 
> > 
> > _______________________________________________
> > This mail is send to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the 
> list, please 
> > visit http://mail.opencms.org/mailman/listinfo/opencms-dev
> > 
> 
> -- 
> +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, 
> please visit http://mail.opencms.org/mailman/listinfo/opencms-dev
> 
> 




More information about the opencms-dev mailing list