Java JAX-RS POST无法将空xlsx作为mime类型返回
下面是我的JAX-RS GET服务的代码Java JAX-RS POST无法将空xlsx作为mime类型返回,java,excel,post,jax-rs,mime-types,Java,Excel,Post,Jax Rs,Mime Types,下面是我的JAX-RS GET服务的代码 @GET @Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") @Path("/xlsReport") public Response viewXlsReport(@QueryParam("paymentIds")String paymentIds) throws IOException { List spaymentIds = Arrays.asL
@GET
@Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@Path("/xlsReport")
public Response viewXlsReport(@QueryParam("paymentIds")String paymentIds) throws IOException
{
List spaymentIds = Arrays.asList(paymentIds.split(","));
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s1 = wb.createSheet("Some Details");
File f = new File("Some Details.xslx");
FileOutputStream fos = new FileOutStream(f);
wb.write(fos);
fos.close();
return Response.ok((Object)file).build();
}
邮政服务就像
@POST
@Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@Path("/exportReport")
@Consumes(MediaType.APPLICATION_JSON)
public Response viewXlsReport(String ids) throws IOException
{
List<string> sIds = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(ids,"&");
// populate sIds , not used in both GET & POST Version
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s1 = wb.createSheet("Some Details");
File f = new File("Some Details.xslx");
FileOutputStream fos = new FileOutStream(f);
wb.write(fos);
fos.close();
return Response.ok((Object)file).build();
}
@POST
@生成(“application/vnd.openxmlformatsofcedocument.spreadsheetml.sheet”)
@路径(“/exportReport”)
@使用(MediaType.APPLICATION_JSON)
公共响应viewXlsReport(字符串ID)引发IOException
{
List sIds=new ArrayList();
StringTokenizer令牌=新的StringTokenizer(ID“&”);
//填充SID,不在GET和POST版本中使用
XSSF工作簿wb=新XSSF工作簿();
XSSFSheet s1=wb.createSheet(“一些细节”);
文件f=新文件(“Some Details.xslx”);
FileOutputStream fos=新的FileOutStream(f);
wb.write(fos);
fos.close();
返回Response.ok((对象)文件).build();
}
问题
- 从GET生成的xlsx打开良好
- 但是POST提供的错误文件格式或扩展名无效
确实不确定代码中有什么错误。问题出在客户端
在GET-request-sending-correct-header-responseType:“arraybuffer”中,在POST中我没有发送此头,因此问题出在客户端 在GET-request-sending-correct-header-responseType:“arraybuffer”中,在POST中,我没有发送此头,因此出现了问题