Jersey作为Oracle的rest架构的开源框架,它既然是servlet,那么它也同样支持跟页面的交互,这里我采用了JSP作为模板来体现跟web page的交互,当然它也支持freemarker、velocity等模板引擎。
?
工程采用maven构建,第一步maven需要引入的lib包
<dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet-core</artifactId> <!-- use the following artifactId if you don't need servlet 2.x compatibility --> <!-- artifactId>jersey-container-servlet</artifactId --> </dependency> <dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-mvc-jsp</artifactId> </dependency> <!-- uncomment this to get JSON support <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> </dependency> --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> <version>2.7.1</version> </dependency> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.11.0</version> </dependency>
?第二步:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- This web.xml file is not required when using Servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>vote</display-name> <!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> <filter> <filter-name>AuthFilter</filter-name> <filter-class>org.ewell.filter.AuthFilter</filter-class> </filter> <filter> <filter-name>jersey</filter-name> <filter-class>com.agenda.base.AppServletContainer</filter-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.agenda.AgendaApplication</param-value> </init-param> <init-param> <param-name>javax.servlet.Filter</param-name> <param-value>org.ewell.filter.AuthFilter</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> <param-value>/.*</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name> &l