考虑3个JPEG文件REST WebService动态提供图像?
- image1.jpg
- image2.jpg
- image3.jpg
对于给定的URL和一组参数,我想服务器选择并返回其中一个图像。
我正在JEE6环境中工作。你会推荐什么方法?
- JSF重定向?
- REST WebService?
- 一个很好的旧servlet?
- ...?
欢迎任何建议!
考虑3个JPEG文件REST WebService动态提供图像?
对于给定的URL和一组参数,我想服务器选择并返回其中一个图像。
我正在JEE6环境中工作。你会推荐什么方法?
欢迎任何建议!
这是我酿造至今:
import org.apache.commons.io.IOUtils;
@Path("/item")
public class MyResource {
@GET
@Path("/object/{id}")
@Produces("image/jpeg")
public byte[] getImageRepresentation(@PathParam("id") int id) {
byte[] bytes = null;
switch (id) {
case 1: bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/img/image01.jpg"));break;
case 2: bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/img/image02.jpg"));
}
return bytes;
}
}
不过好奇的替代方法!谢谢! J. :-)
而权限? – 2010-09-21 14:12:40