Thanks Perre-Yves.
I may missed something here.
Are you saying that I can instantiate a bean in the servlet and then use it
the way you coded? Can you show me a little more details? I know that one
can instantiate a class (bean) in the servlet and in order for a jsp to use
it, one have to save the object in a session or request or something like
that. Thanks again for your help.
Jian
-----Original Message-----
From: Pierre-Yves Saumont [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 23, 2001 9:34 AM
To: [EMAIL PROTECTED]
Subject: Re: Get initial properties from a property file for JSP
Hi,
There are several ways to do this, using scriptlets, beans or taglib. I
suggest you forget about scriptlets as much as you can and start with a
bean, which is much easier than designing a taglib.
To make it through a bean, you just have to use a class of your own that to
the job you need (reading the propety file) and make this class a bean. If
you already used a bean in your servlet, you're done! if not, you will have
to extract the relevant code from your servlet and put it into a bean.
The only problem with a bean is that it does not have access to the context
so it can't use relative path to access the property file.
One solution is the following :
<jsp:useBean id='mybean' class='my.package.MyBean' scope='session'/>
<jsp:setProperty name='mybean' property='rootDocumentPath' value='<%=
getServletConfig().getServletContext().getRealPath("/") %>'/>
<jsp:setProperty name='mybean' property='propFile' value='mypropfile'/>
<jsp:getProperty name='mybean' property='propFile' value='aproperty'/>
If you want non scriptlet at all, you'll have to write your own taglib. Of
course, the tag you will design for this purpose will make use of your
bean:-)
For more information about designing a taglib, you might choose to subscribe
to a more specific list.
Pierre-Yves
-----Message d'origine-----
De : A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]De la part de
Ouyang, Jian
Envoy� : jeudi 23 ao�t 2001 13:40
� : [EMAIL PROTECTED]
Objet : Get initial properties from a property file for JSP
Hi,
I have set up for a servlet to read in properties from a property file in
its init() method.
It works fine. I am thinking to do the same in a JSP file. Can anybody tell
me how to set it up so I can in a JSP file read in the properties for the
application once and only once? I am using weblogic 5.1. Thanks.
Jian
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html