Hello every Body,
i am just new with jeresy web applications (restfull applications), so now i know how deal with @Get, but the problem how to make it with @put, @post, and @ delete
i will write a very simple example.
import java.util.ArrayList;
public class ArrList1 {
protected static ArrayList col1 = new ArrayList();
public void arrList() {
col1.add("hallo");
col1.add(2);
col1.add(3);
col1.add(4.0);
col1.add(5.25);
col1.add(6);
}
}
Now the Jeresy Code
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/ArrayList2Jersy")
public class RestfullJersy extends ArrList1{
@GET
public Response arrList() {
ArrList1 read = new ArrList1();
read.arrList();
//print the value of the cells which is stored in the the Arraylist
System.out.println("");
for (int i = 0; i < col1.size(); i++){
Object item = col1.get(i);
}
String result = " Output: \n\nArrayList Output: \n\n" + item ;
return Response.status(200).entity(result).build();
}
}
web.xml
HTML Code:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>pal.restfulservice</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/jeresy/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
http://localhost:8080/RestFul/jeresy/ArrayList2Jersy and i will get all element in the arraylist (where RestFul is the name of the Project)
now all what i want how to write code to add new element in the arraylist @POST or update it @PUT or remove it @DELETE
for example if i want to add new element col1.add(34); how to write it with @POST and what should the URL to call it?