java - 如何在 HttpServletResponse 中设置表标题?
问题描述
我们正在使用 broser 中显示文件
shiowMethod(final String viewType, final String filename,HttpServletResponse response){
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Length", String.valueOf(docasnyObsah.getSoubor().length));
response.setHeader("Cache-Control", "private");
response.setHeader("Pragma", "private");
response.setHeader("Content-Disposition", ContentDisposition.create(zobrazeni , "my_file.pdf",
"My title"));
response.flushBuffer();
}
public static String create(final String viewType, final String filename, final String fieldName) {
try {
final String encoded = URLEncoder.encode(filename, StandardCharsets.UTF_8.name()).replace("+", "%20");
if(fieldName.isEmpty()){
return String.format("%1$s; filename*=UTF-8''%2$s; filename=\"%2$s\"", viewType, encoded);
}
else {
String test = String.format("%1$s; filename*=UTF-8''%2$s; name=\"%3$s\"; filename=\"%2$s\"", viewType, encoded, fieldName);
return test;
}
} catch (final UnsupportedEncodingException e) {
throw new ShouldNotHappenRuntimeException(e);
}
}
我希望这会将选项卡的标题设置为“我的标题”,但不是这个,而是 viewType 显示如下
发送到 submetod 的值是
viewType = "inline"
filename = "my_file.pdf"
fieldName = "My title"
我需要更改什么才能设置 html 页面选项卡名称?
解决方案
推荐阅读
- vb.net - 在 vb.net 中对 DataTable 中的重复行求和
- mysql - 在插入时在 mysql 中创建触发器,它比较添加行的字段
- mongodb - 通过 mongoose-double 插入数据后找不到文档
- pentaho - 基于某些条件加载水壶的 Pentaho 数据集成问题
- c++ - C++/G++ 包括来自另一个文件夹的标题
- matlab - Matlab排序矩阵取决于降序和升序两列
- javascript - 如何从 reactjs 中的 iframe 订阅在 dojo 中发布的事件
- mongodb - 在两个数组中查找并显示找到的一个
- reactjs - React 组件中的属性始终未定义
- android - 从子活动更改 BaseActivity 的工具栏标题