我必须使用jersey在eclipse中编写restful web-service,我必须从我的数据库中获取不同的文件(.jpeg,.PDF,.docs等..)。它应该获取文件及其内容。这样我就可以在html中使用这个web服务和ajax来调用web-service
到目前为止,我已经完成了代码..@POST
@Path("/info/{username}/{projectid}")
@Produces("application/json")
public LinkedList<Statusis> responseMsg2(@PathParam("username") String uname, @PathParam("projectid") String pid ) throws SQLException {
Map<String, Statusis> status = new HashMap<String, Statusis>();
Connection conn = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager
.getConnection("jdbc:sqlserver://servername:1433;databaseName=AMIS_TEST;user=xyz;password=****@123");
String query = "usp_get_project_escalatedissues '" + uname + "' , '" + pid +"'";
PreparedStatement ps = conn.prepareStatement(query);
rs = ps.executeQuery();
if(rs!=null)
{
int count = 0;
while (rs.next()) {
Statusis statusis = new Statusis();
statusis.setQueryID(rs.getString(1));
statusis.setTitle(rs.getString(2));
statusis.setIssueDescription(rs.getString(3));
statusis.setClarificationId(rs.getString(4));
status.put(statusis.getQueryID()+count,statusis);
count++;
}
}
else
{
return null;
}
} catch (Exception err) {
System.out.println("ERROR: " + err);
} finally {
rs.close();
conn.close();
}
Response.ok().header("Access-Control-Allow-Origin", "*").build();
return new LinkedList<Statusis>(status.values());
}
AJAX CALL IS:
$.ajax({
url:serviceurl1 +'/' +uname + '/' +selctedprjt ,
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
async : true,
crossDomain: true,
success: function(data) {
alert("Web service call succeeded." );
$("#issuestable tbody tr").remove();
if(data.status.length != undefined)
{
$.each(data.status, function (key, value)
{
$("#issuestable").append('<tbody><tr><td>'+value.queryID+'</td><td>'+value.title +'</td></tr></tbody>');
}else
{
//alert("in else");
}
},
error: function (error)
{
alert('ERROR has occurred!');
alert(JSON.stringify(error))
}
})
});
我在我使用的数据库程序中有两个文件.PDF和.JEPG文件返回这些文件.. 任何人都可以告诉我如何在我的网络服务中获取它们以及我正在检索的字段