java - Tomcat with Rest - HTTP Status 500 - Servlet execution threw an exception -
i'm trying code simple restful webservice, following tutorials. i'm searched everywhere can't find solution after several tries fit problem. i'm using netbeans 8.0.2 , apache tomcat 8.0.15 (installed netbeans). i've had several issues tomcat managed solve them, except one.
helloworld.class
package com.example; import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.produces; import javax.ws.rs.queryparam; import javax.ws.rs.core.mediatype; import org.codehaus.jettison.json.jsonexception; import org.codehaus.jettison.json.jsonobject; //path: http://localhost/<appln-folder-name>/hello @path("/hello") public class helloworld { // http method @get // path: http://localhost/<appln-folder-name>/hello/world @path("/world") // produces json response @produces(mediatype.application_json) public string dohello(){ jsonobject obj = new jsonobject(); try { obj.put("hello", "world"); } catch (jsonexception e) { // todo auto-generated catch block } system.out.println(obj.tostring()); return obj.tostring(); } }
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>restful_example</display-name> <!-->project name<--> <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>com.example</param-value> <!-->package name<--> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey rest service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
the error
to test service, followed this: https://netbeans.org/kb/docs/websvc/rest.html#test-rest
what doing wrong?
you have jar conflicts problem. review libs. maybe using jars different jersey versiosn
Comments
Post a Comment