Jersey is a RESTful request Service Java framework, similar to the struts framework used by regular Java programming, and is primarily used to process the business logic layer. Similar to struts, it can also be integrated with the hibernate,spring framework. Because struts2+hibernate+spring integration in the market share is too high, so few people to pay attention to Jersey. So the introduction of Jersey on the internet is very few. But it really is a very good framework. For a request-only service, you may even need to give a URI to complete the operation for the Get,delete request. A simple example: if you want to get all the data in the server database, you can set the path in the browser or by using the Ajax get method, for example: localhost:8080/student
(project name)/studentinfo
(Project service overall prefix)/student (
endorsement for handling student objects)/getstudentinfo (
Last prefix)。 This will allow all student information to be obtained. You can choose the return type of the data obtained by Get: json,xml,text_html (String). Once obtained, you can plug this data into HTML or JSP pages via JS. Here's the explanation: the settings for Web.:<!--Define the jersey interceptor--
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>
Com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<!--the folder where the service class is located--
<param-value>com.mirrors.action</param-value><!-- The reason I'm defined as Com.mirrors.action is that the class in this package acts like the action layer class in Struts--! >
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/new/*</url-pattern>
<!--project Service overall prefix --
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>studentaction.java Some code: @Component
@Path ("/student")
//Handling endorsement of Student objects
public class Studentaction
{
Private Studentdao Studentdao;
public void Setstudentdaostudentdao Studentdao)
{
This.studentdao =studentdao;
}
@GET
//How to get
@Path ("Getstudentinfo")//
Last prefix@Produces ({Mediatype.application_json})
//return type is a JSON array of student objects
Public list<student> Gettrade () {
return Studentdao.getstudent ();
}} The processing of such a Get method is finished, followed by the foreground extraction method, you can control the JSON array in the way the page is rendered by JS. Jersey a total of 4 processing methods, namely: @GET, @POST, @DELETE, @PUT.