Results 1 to 2 of 2
  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    187
    Rep Power
    2

    Default How to write jeresy web applications code using @POT, @PUT @DELETE

    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.

    Java Code:
    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
    Java 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
    XML 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?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to write jeresy web applications code using @POT, @PUT @DELETE

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Code to delete a particular record
    By lokeshnaalla in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 10-25-2012, 09:23 AM
  2. The code didn't delete the text file
    By amyng in forum New To Java
    Replies: 3
    Last Post: 05-01-2012, 06:37 AM
  3. Search and Delete code help
    By nyy132 in forum New To Java
    Replies: 1
    Last Post: 04-17-2012, 10:57 PM
  4. Add , edit ,delete code in struts
    By sandy1000 in forum Web Frameworks
    Replies: 0
    Last Post: 12-28-2010, 06:25 AM
  5. How to delete pre-generated code?
    By Terentius in forum NetBeans
    Replies: 0
    Last Post: 08-19-2008, 04:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •