I'm only a beginner but I have gone through one beginners Java training course where we also covered some aspects of REST so I'm starting to understand things a little bit better. I would really like to understand more about servlets and how web.xml is used to set them up. The below is a web.xml that I was using on my project while I was on this training course.
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-
class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.arpit.java2blog.controller</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Righ now I can only understand some of it. I can understand some of what <servlet-name>
, <servlet-class>
, <servlet-mapping>
and <url-pattern>
do.
But I'm really struggling to understand what <init-param>
, <param-name>
and <param-value>
in generally do. I've been trying to google to find some information that would explain these in very simplistic manner but I have not had much joy.
I really want to understand what these two sections below do:
`<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.arpit.java2blog.controller</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>`
I can understand bit of what the first section relates to because my controller classes are in package <param-value>org.arpit.java2blog.controller</param-value>
. But what does and why is the param-name as com.sun.jersey.config.property
? I cannot find any package with this name.
I understand the the second init=param section has something to do with the jersey-json jars and that's about it.
I would be genuinely grateful if someone could explain some of these things in a very simplistic English if possible (English is not our native language in Estonia). I'm working really hard to become a better in programming and I could use bit of help.
Kind regards.