1
我想通過Jersey將URL綁定到JSP。我試圖做一個笑話網站,我想:URL綁定到JSP的Jersey問題
(1)/笑話=笑話名單 (2)/笑話/ 213 =頁面的笑話ID爲213
然而,( 2)似乎沒有工作,我不知道。
這是我與球衣的servlet
<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>
這裏的web.xml是我的資源:
@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>";
}
}
我是不是做錯了什麼還是...?使用碼頭6.1,澤西1.6
任何幫助會感激=)進出口
oi,如果生活可能如此簡單,我也試圖去測試。但最後我需要{id}/*,因爲url會是/ jokes/123/yo-mama-is-so -... – somid3 2011-04-08 01:31:49
好的。那麼,前者的格式不正確,請在這裏指定:http://jsr311.java.net/nonav/releases/1.0/javax/ws/rs/Path.html。這就是說,試試@Path(「/笑話/ {id}/{title}」)。 – drew 2011-04-08 01:33:18