Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to write jeresy web applications code using @POT, @PUT @DELETE

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    46
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

    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?


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

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

    This thread has been cross posted here:

    http://www.java-forums.org/advanced-java/80361-how-write-jeresy-web-applications-code-using-pot-put-delete.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  3. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    jps (July 25th, 2013)

Similar Threads

  1. [Help] How to delete code sipush in ola 5 ?
    By hiphopxalon in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 20th, 2013, 11:53 AM
  2. How to put my code onto the window.
    By Shzylo in forum Java Theory & Questions
    Replies: 1
    Last Post: December 18th, 2012, 09:34 PM
  3. this is code for delete button,is there any errors??,plz help guys
    By live89 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 20th, 2012, 12:56 PM
  4. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM