Note that there are some explanatory texts on larger screens.

plurals
  1. POGet configuration data from web.xml when using a jersey ServletContainer
    primarykey
    data
    text
    <p>I'm creating a webapp in Tomcat using jersey. I haven't created a Servlet, I just use the jersey ServletContainer and some Resource classes. </p> <p>My web.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; &lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt; com.sun.jersey.spi.container.servlet.ServletContainer &lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;com.mycompany.myproduct.rest&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>My webapp needs to read some configuration values. I have the impression that a good way to do this is with context-Params, like this:</p> <pre><code>&lt;web-app&gt; ... &lt;context-param&gt; &lt;description&gt;This is a context parameter example&lt;/description&gt; &lt;param-name&gt;ContextParam&lt;/param-name&gt; &lt;param-value&gt;ContextParam value&lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt; </code></pre> <p>Is this the best way? How can I access these context params from my resource classes?</p> <p>Here's an example resource class:</p> <pre><code>@Path("/api/ping") public class PingResource { @GET @Produces(MediaType.TEXT_PLAIN) public String helloWorld() { return "pong"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload