2017年8月29日 星期二

Learning Jersey in web Step


1 First  jersey project 

  • eclipse Mar2 Release - 內含 M2E(Maven Plugin)
  • Tomcat 8.0.22
  • Jersey 2.17


a. New -> Maven project -> maven-archetype-webapp

b. Group Id:  tw.com.edittw
    artifactId: jerseySample

c. Setting target runtimes: apache tomcatV8.0

d. Select maven -> add dependency


e.  add the information
  • Group Id : org.glassfish.jersey.containers
  • Artifact Id : jersey-container-servlet
  • Version : 2.17

f. Run maven install




Ref: Frist Jersey


2 Hello Jersey


1. Setting web.xml 

<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<!-- Add the jersey to start -->
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Add the package that will search for path in com.javatpoint.rest -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.javatpoint.rest</param-value>
</init-param>
<!-- In need you can add logging -->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
<!-- Enable Tracing support. -->
<init-param>
<param-name>jersey.config.server.tracing</param-name>
<param-value>ALL</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping all the /rest/* files and request to the jersey -->
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
2. Programming the java and index link

And  the first hello jersey
Note it is using the GET method


Type the Simple hello will show the message



















沒有留言:

張貼留言