久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 JAX-RS 中設(shè)置響應(yīng)標(biāo)頭,以便用戶(hù)看到 E

How to set response header in JAX-RS so that user sees download popup for Excel?(如何在 JAX-RS 中設(shè)置響應(yīng)標(biāo)頭,以便用戶(hù)看到 Excel 的下載彈出窗口?)
本文介紹了如何在 JAX-RS 中設(shè)置響應(yīng)標(biāo)頭,以便用戶(hù)看到 Excel 的下載彈出窗口?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我編寫(xiě)了使用 REST JAX-RS 生成 Excel 文件的代碼,并確認(rèn)生成的 Excel 文件位于 GlassFish 服務(wù)器目錄中.

I wrote code that generate Excel file using REST JAX-RS and I confirmed that the generated Excel file is in GlassFish server directory.

但我的目標(biāo)是當(dāng)用戶(hù)單擊按鈕(生成 Excel .xls)時(shí),我希望顯示下載彈出窗口,詢(xún)問(wèn)用戶(hù)是保存還是打開(kāi) .xls 文件,就像任何其他用于下載任何類(lèi)型的 Web 服務(wù)一樣文件.

But my goal is when user click on the button (which generate Excel .xls), I want download popup to show up asking user whether to save or open the .xls file just like any other web services doing for downloading any type of files.

根據(jù)我的搜索,步驟是:

According to my search, the step is:

  1. 生成 Excel .xls(完成)

  1. generate Excel .xls (DONE)

將excel寫(xiě)入流

在 JAX-RS 文件中,將響應(yīng)頭設(shè)置為類(lèi)似,

in JAX-RS file, set response header to something like,

字符串文件名 = "Blah_Report.xls";response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

String fileName = "Blah_Report.xls"; response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

我的問(wèn)題是我在 JAX-RS 文件中執(zhí)行所有這些操作,但我沒(méi)有可用的 HttpServletResponse 對(duì)象.

My question is I'm doing all of this in JAX-RS file and I don't have HttpServletResponse object available.

根據(jù)來(lái)自的回答將響應(yīng)標(biāo)頭添加到 JAX-RS Web 服務(wù)

他說(shuō):

您可以注入對(duì)實(shí)際的 HttpServletResponse 通過(guò)Web 服務(wù)中的 @Context 注釋并使用 addHeader() 等添加您的標(biāo)題.

You can inject a reference to the actual HttpServletResponse via the @Context annotation in your webservice and use addHeader() etc. to add your header.

如果沒(méi)有示例代碼,我真的無(wú)法弄清楚這到底意味著什么..

I can't really figure what exactly that means without sample code..

推薦答案

您不需要 HttpServletResponse 在響應(yīng)上設(shè)置標(biāo)頭.您可以使用javax.ws.rs.core.Response.只需讓您的方法返回響應(yīng)而不是實(shí)體:

You don't need HttpServletResponse to set a header on the response. You can do it using javax.ws.rs.core.Response. Just make your method to return Response instead of entity:

return Response.ok(entity).header("Content-Disposition", "attachment; filename="" + fileName + """).build()

如果您仍想使用 HttpServletResponse,您可以將其注入到類(lèi)字段之一,或使用屬性或方法參數(shù):

If you still want to use HttpServletResponse you can get it either injected to one of the class fields, or using property, or to method parameter:

@Path("/resource")
class MyResource {

  // one way to get HttpServletResponse
  @Context
  private HttpServletResponse anotherServletResponse;

  // another way
  Response myMethod(@Context HttpServletResponse servletResponse) {
      // ... code
  }
}

這篇關(guān)于如何在 JAX-RS 中設(shè)置響應(yīng)標(biāo)頭,以便用戶(hù)看到 Excel 的下載彈出窗口?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: caoporn视频在线| 中文字幕一区二区视频 | 日韩国产在线 | 97av视频| 天天夜夜操 | av免费在线观看网站 | 亚洲美女网站 | 91视频入口 | 国产高清在线 | 天天看片天天干 | 欧美在线一区二区三区 | 久久久久网站 | 亚洲一区视频在线 | 人人看人人搞 | 日日爱视频 | 久久久久久99 | 欧美999| 欧美中国少妇xxx性高请视频 | 亚洲精品在线免费看 | 国产主播第一页 | 99久久精品免费看国产小宝寻花 | 亚洲精品第一 | 国产一级一级毛片 | 亚洲第一中文字幕 | 国产高清免费 | 久久久久国色av免费观看性色 | 国产午夜精品视频 | 日本人爽p大片免费看 | 男女又爽又黄视频 | 亚洲一区国产精品 | 男女爱爱福利视频 | 一区二区在线免费观看 | 国产欧美一区二区三区在线看 | 亚洲自拍偷拍视频 | 免费99精品国产自在在线 | 亚洲综合字幕 | 一区二区视频在线 | 午夜影院黄 | 亚洲精品久久久9婷婷中文字幕 | 国产有码 | 国产成都精品91一区二区三 |