How to pass a reference when initializing a servlet
How would I go about passing a reference to the initialization of a servlet?
So, let's say I have something like this in my web.xml:
<开发者_开发技巧servlet>
<servlet-name>RestTestServlet V3.1</servlet-name>
<servlet-class>com.xxx.servlet.RestTestServlet</servlet-class>
<init-param>
<param-name>serviceConsumerKey</param-name>
<param-value>com.xxx.oauth.ConsumerKey</param-value>
</init-param>
</servlet>
When I try to get the parameter, of course I just get the literal string value ("com.xxx... etc).
The com.xxx.oauth.ConsumerKey is a string bean I pull from JNDI, but I'm not sure how to get the servlet to be aware of it. I'm using Spring.
Is there a way to do this via the web.xml? If not, how would you go about doing what I'm trying to do?
The normal Spring approach would be to not write your own servlets, but rather use the Spring WebApplicationCOntext together with a DispatcherServlet. I.e., your servlet would be replaced by a spring bean, configured to handle certain requests and injected with the JNDI object.
精彩评论