小编use*_*256的帖子

@PathParam获取空值

感谢您的帮助,即使您刚刚阅读它.

问题:返回值为null为什么?检查了很多论坛,一切似乎都很好,但事实并非如此.

package pack.bb;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("path")
public class test {
    @GET
    @Path("{sorted}")
    public String getsortedContactList(@PathParam("list") String list) //throws SQLException
    {
        System.out.println("GET list: " + list);
        return "get " + list;
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用localHost 8080使用它

"localHost:8080/testCap/api/path/aaaa"
Run Code Online (Sandbox Code Playgroud)

这是web.xml文件.我认为这是正确的,因为我在其他项目中使用它

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Factorial_RESTapp</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>Jersey REST Service</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>pack.bb</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/api/*</url-pattern>
  </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

运行后我在控制台中得到这个结果: …

java rest web-services

0
推荐指数
1
解决办法
5312
查看次数

标签 统计

java ×1

rest ×1

web-services ×1