开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜