在 Netbeans 中,web.xml 位于
WAR-Project with Maven
- Web Pages
- WEB-INF
- web.xml
在文件夹结构中,它位于:
WAR-Project with Maven
- src
- main
- webapp
- WEB-INF
- web.xml
在那里你可以定义 Jersey Servlet:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<!-- Jersey -->
<servlet>
<servlet-name>Jersey Web Application</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>package.path.to.your.rest.service;</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
现在您可以通过以下 URL 访问您的 REST 服务:
localhost:8080/HelloWorld/rest/test/printHello