java - The requested resource is not available when trying to do get -
i want make url work
http://localhost:8080/homecontroller/students/getallstudents
and error:
the requested resource not available
here's code:
package controller; @path("/students") public class homecontroller { @path("/add") @post @produces(mediatype.text_plain) @consumes(mediatype.application_json) public static string add(student student) throws exception { @path("/getallstudents") @get @produces(mediatype.text_plain) public string getallstudents() throws exception { return "dasda"; } } } <?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" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>studentsservice</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> 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 rest service</servlet-name> <url-pattern>/homecontroller/*</url-pattern> </servlet-mapping> </web-app>
after first link works, want link work well.
http://localhost:8080/students/getallstudents
@path("/students") public class homecontroller { @path("/add") @post @produces(mediatype.text_plain) @consumes(mediatype.application_json) public static string add(student student) throws exception { @path("/getallstudents") @get @produces(mediatype.text_plain) public string getallstudents() throws exception { return "dasda"; } } } <?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" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>studentsservice</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> name_of_teh package(e.g. if homecontroller lies in com.urname.controller.homecontroller, value com.urname.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_rest_service</servlet-name> <url-pattern>/homecontroller/*</url-pattern> </servlet-mapping> </web-app>
the @path should contain never have slash @ end, sine makes path /students//. additionally, controller package has not been mapped jersey packages, should find controllers. please try corrected code snippet posted above.
Comments
Post a Comment