Reputation: 183
Thank you for your help even if you just read it.
Problem: return value is null why? Have checked many forums and everything seems to be fine, but isn't.
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;
}
}
I am using this using localHost 8080
"localHost:8080/testCap/api/path/aaaa"
This is web.xml file. I think it is correct because I was using it in other projects
<?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>
After running I get this result in console:
GET list: null
Upvotes: 0
Views: 6793
Reputation: 53462
It should be
@Path("/{list}")
public String getsortedContactList(@PathParam("list") String list)
Instead of {sorted}
. The first @Path identifies the section in the url and @PathParam then tells which variable is used for it, so they have to match. The last one, variable name, can be anything.
Upvotes: 5