1

我在网上看到很多这样的例子,比如......

<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
     version="3.0">
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>

但是,这对我永远不起作用。我收到一个错误

java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name javax.ws.rs.core.Application

那么,能够直接在 servlet-name 中使用类名的秘诀是什么?

4

2 回答 2

2

我认为@davideconsonni 几乎是正确的:

<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>javax.ws.rs.core.Application</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello/*</url-pattern>
</servlet-mapping>
于 2013-03-05T21:46:30.317 回答
0

首先声明你的servlet:

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/hello/*</url-pattern>
</servlet-mapping>
于 2012-08-03T08:20:22.770 回答