我的示例是使用 ImplicitViewable 配置特性(参见WEB-INF/web.xml
参考资料)和隐式可视化方法,其中 JSP 页面通过放置在与适当资源包名称对应的正确路径进行映射。它不起作用。我应该怎么做?
如果${it.name}
写入 jsp 文件,资源类也有它的私有名称变量,那么什么也不会发生。我无法实现连接。
这是 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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.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>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>com/sun/jersey/samples/bookstore/resources/Hotelstore/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是 com/sun/jersey/samples/hotelstore/resources/ 包内的 hotelstore.java
@Path("/")
@Singleton
public class Hotelstore {
private final Map<String, Hotelitem> items = new TreeMap<String, Hotelitem>();
private String name;
public Hotelstore() {
setName("Otel sheriton");
getItems().put("1", new Hotelitem("Sheriton", "Maslak","Big boss", new Room[]{
new Room(1,"Cedric","dolu"),
new Room(2,"Eigner","dolu"),
new Room(3,"Deli","dolu"),
new Room(4,"","bos")
}));
}
@Path("Hotelitems/{itemid}/")
public Hotelitem getItem(@PathParam("itemid") String itemid) {
Hotelitem i = getItems().get(itemid);
if (i == null)
throw new NotFoundException("there is no room number"+itemid);
return i;
}
public long getSystemTime() {
return System.currentTimeMillis();
}
public Map<String, Hotelitem> getItems() {
return items;
}
getter setter for name.
......
}