我正在尝试通过Jersey将URL绑定到JSP。我想制作一个笑话网站,我想:
(1)/ jokes =笑话列表 (2)/ jokes / 213 =与id 213的笑话页面
然而,(2)似乎没有用,我不知道。
这是我的带有jersey servlet的web.xml
<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.packages</param-name>
<param-value>com.moesjokes.site.server.resources</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.Redirect</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<!--<url-pattern>/jokes</url-pattern>-->
<url-pattern>/jokes/*</url-pattern>
</servlet-mapping>
这是我的资源:
@Path("/")
public class Jokes {
@GET
@Path("/jokes")
@Produces("application/xml")
public Viewable getAll() {
JspPage jsp = new JspPage(Pages.WELCOME);
JspGlobalWidget global = jsp.getGlobal();
JokesWidget jokes = new JokesWidget(jsp);
jokes.setContents( new ContentServcies().getLatestContents(1, 20) );
Map<String, String> map = new HashMap<String, String>();
map.put("jokes", jokes.toHtml());
return new Viewable("/jsp/jokes/index.jsp", map);
}
@GET
@Path("/jokes/{id}/*")
@Produces("application/xml")
public String get(@PathParam("id") String id) {
return "<test>" + id + "</test>";
}
}
我做错了什么还是......?我使用Jetty 6.1,Jersey 1.6
任何帮助都会被欣赏=)
答案 0 :(得分:1)
从
更改路径@Path("/jokes/{id}/*")
要
@Path("/jokes/{id}")
我不相信前者格式正确。