contexts [message #121489] |
Sun, 17 July 2005 04:06  |
Eclipse User |
|
|
|
I'm not even sure this question make any sense, but I'll try...
I have a dynamic web project that defines a servlet. this servlet has some
configuration parameters, defined in the META-INF/context.xml file. I use
tomcat 5.5 .
I'd like to have 2 contexts (I hope I'm using the correct terminology) that
run the same servlet, with different configurations. For example:
http://myhost:8080/ctx1/ will invoke the servlet with configuration C1
and
http://myhost:8080/ctx2/ will invoke the same servlet with configuration
C2
How do I do that?
|
|
|
Re: contexts [message #121903 is a reply to message #121489] |
Mon, 18 July 2005 12:39  |
Eclipse User |
|
|
|
Originally posted by: non.onon.com
I'm not sure if the web tools project can help you with this. You need to
edit your web.xml file to define the same servlet class twice -- once for
each name. E.g.:
<servlet>
<servlet-name>ctx1</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class >
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/context1.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ctx2</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class >
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/context2.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ctx1</servlet-name>
<url-pattern>/ctx1/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ctx2</servlet-name>
<url-pattern>/ctx2/*</url-pattern>
</servlet-mapping>
Then, inside your servlet's init() method, you need to have
String ctxFile = getServletConfig().getInitParameter("config");
InputStream input =
getServletContext().getResourceAsStream(ctxFile);
// parse your input stream
I would recommend looking up a Servlet tutorial. I didn't actually run this
code, but this is the general gist.
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
I hope this helps.
Adam
"Zohar" <david_fire4@hotmail.com> wrote in message
news:dbd3ij$ak9$1@news.eclipse.org...
> I'm not even sure this question make any sense, but I'll try...
> I have a dynamic web project that defines a servlet. this servlet has some
> configuration parameters, defined in the META-INF/context.xml file. I use
> tomcat 5.5 .
> I'd like to have 2 contexts (I hope I'm using the correct terminology)
> that run the same servlet, with different configurations. For example:
> http://myhost:8080/ctx1/ will invoke the servlet with configuration C1
> and
> http://myhost:8080/ctx2/ will invoke the same servlet with configuration
> C2
>
> How do I do that?
>
|
|
|
Powered by
FUDForum. Page generated in 0.02395 seconds