java - 设置 mime 类型

标签 java playframework playframework-1.x

我想编写一个 Excel 并将其作为使用 Play framework 1.x 的应用程序中的响应发送给用户。但我不确定如何设置响应content-type/MIME-type以返回doc或excel文件。

让我知 Prop 体步骤。

最佳答案

来自the documentation :

To serve binary data, such as a file stored on the server, use the renderBinary method. For example, if you have a User model with a play.db.jpa.Blob photo property, add a controller method to load the model object and render the image with the stored MIME type:

public static void userPhoto(long id) { 
    final User user = User.findById(id); 
    response.setContentTypeIfNotSet(user.photo.type());
    java.io.InputStream binaryData = user.photo.get();
    renderBinary(binaryData);
} 

关于java - 设置 mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14545771/

相关文章:

java - 如何修复 java.lang.UnsupportedClassVersionError : Unsupported major. 次要版本

json - 具有 json 解析器的单元测试 Play Controller 操作

playframework - 如何在 play framework 1.2.x 中显示自定义 400 错误页面?

java - 操作系统错误: [Errno 2] No such file or directory Play framework runs in Java

java - Play 框架中的 Cron Job

java - 无法从TemporalAccessor获取即时消息:{},ISO解析为java.time.format.Parsed类型的2018-01-01

java - mongodb 查找并返回 id 作为字符串 - java

scala - 找不到类型 Seq[models.Comment] 的 Json 格式化程序 尝试为此类型实现隐式格式

关于线程使用的 Java RMI 规范 : "..may or may not execute in a separate thread"

java - Play 1.x 和 Akka 可以一起使用吗?