create a bean on webapp startup

M

Mounir AITTAHAR

Hi,

Unsuccessfully web browsing makes me come here.

I wonder if it's possible to create a bean (used by <jsp:use-bean>) on
startup, also through web.xml. I've seen it is possible to launch a
servlet with <load-on-startup> xml element, but, as I believe I've
understood, it is NOT a persistent object.

So, i'm asking if :
- is this possible to create a persistent object through a servlet
lauched at startup ?
- is there a different way ?

Regards,
 
M

Mounir

Hi all,

It was very simple : I've created the bean through a loaded-on-startup
servlet, and added to the servlet context :

web.xml :
<servlet>
<servlet-name>aServlet</servlet-name>
<servlet-class>package.of.the.servlet.aServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet>

Source part of aServlet.init():
{
ServletContext context=getServletContext();
context.setAttribute("beaname",beanobjet);
}

And in jsp files :

<jsp:use-bean id="beaname" scope="application
class="package.of.the.bean.BeanObject"
type="package.of.the.bean.BeanObject"/>

(type is optionnal here)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top