后端代码:
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
@Path("/t")
public class ImageAPI {
@Path("/images")
@GET
public void showImg(@PathParam("name") String imageName, @PathParam("type") String type,
@Context HttpServletResponse response) throws IOException {
InputStream inputStream = null;
OutputStream out = null;
try {
File file = new File("D:\\t.png");
inputStream = new FileInputStream(file);
out = response.getOutputStream();
// pic size = 1M
byte[] bytes = new byte[1024 * 1024];
int len = 0;
while ((len = inputStream.read(bytes)) > 0) {
out.write(bytes, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputStream != null)
inputStream.close();
if (out != null)
out.close();
}
}
}
前端:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div>hello world</div>
<img alt="" src="http://127.0.0.1:8080/Bank/api/1.0/t/images">
</body>
</html>
分享到:
相关推荐
NULL 博文链接:https://1197581932.iteye.com/blog/2400218
NULL 博文链接:https://1197581932.iteye.com/blog/2400927
jersey restful webservice最新版资源共享,欢迎下载!
NULL 博文链接:https://1197581932.iteye.com/blog/2409545
Restful Jersey webservice:包括Jersey实现的Restful webservice工程,这是一个比较实用的实例项目,在Tomcat中能实际正常运行起来。
NULL 博文链接:https://liangyingying1117.iteye.com/blog/2061846
jersey-1.1.2 restful webservice
Jersey和Tomcat构建RESTful WebService及其调用
基于REST的软件体系结构风格(Software Architecture Style)称之...按照REST原则设计的软件、体系结构,通常被称为“REST式的”(RESTful),在本文中以下称之为 RESTful Web服务,以便于和基于SOAP的Web服务区别。
在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用
一个使用Jersey和Tomcat搭建的RESTful WebService,实现了使用Get,POST,PUT,DELETE方法来操作资源,极具构建RESTful WebService的参考价值。
RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状态的,发布和调用都非常的轻松容易。 下面写一个最简单的Hello World例子,以便对RESTful WebService有...
Restful WebService与Spring集成
Java restful和webservice接口, WebService有两种方式,一是SOAP方式,二是REST方式。SOAP是基于XML的交互,WSDL也是一个XML文档,可以使用WSDL作为SOAP的描述文件;REST是基于HTTP协议的交互,支持JSON、XML等交互...
NULL 博文链接:https://royal2xiaose.iteye.com/blog/1489649
Web Service 必看之书,采用Restful风格开发
使用restlet实现了最简单的restful webservice,可以直接部署运行。可以作为restful webservice开发的基础环境。
很少有的关于restful webservice视频,希望对大家有点帮助,最近下载资料有些频繁,赚点学分。
使用eclipse创建restful webservice 工程.d
开发RESTful WebService 示例