3、Manipulating Results 结果操作

修改默认的content-type

运行结果的content-type是通过response中的返回值来自动推测的,

    例如:
    
        val textResult = Ok("Hello World!")

将自动设置 Content-Type 的头为 text/plain。

   val xmlResult = Ok(<message>Hello World!</message>)

将自动设置Content-Type为application/xml.

这是一种非常不错的使用方法,但是有的时候想指定特定的Content-type,只需要使用as(newContentType)方法在result上,就可以创建一个值相同Content-type不同的

resultval htmlResult = Ok(<h1>Hello World!</h1>).as("text/html")

或者使用

val htmlResult2 = Ok(<h1>Hello World!</h1>).as(HTML)

设置和丢弃cookies

我们可以简单的去操作cookies,将cookie放入到返回浏览起的response中
增加东西到cookies中

val result = Ok("Hello world")
  .withCookies(Cookie("theme", "blue"))
  .bakeCookies()

在cookies中删除

val result2 = result.discardingCookies(DiscardingCookie("theme"))

在设置和删除共同在同一个命令中进行操作

val result3 = result.withCookies(Cookie("theme", "blue")).discardingCookies(DiscardingCookie("skin"))

操纵HTTP标头

您还可以向结果添加(或更新)任何HTTP标头:

val result = Ok("Hello World!").withHeaders(
  CACHE_CONTROL -> "max-age=3600",
  ETAG -> "xx")

请注意,如果原始结果中存在对应的值,则设置HTTP标头将自动丢弃之前的值

设置编码类型:

在http返回中,设置正确的编码类型是非常重要的,Play是默认使用utf-8的
charset的作用是将返回的信息通过某种编码方式转化成对应的socket传递的字节,通过;charset=xxx 来设置

class Application @Inject()(cc: ControllerComponents) extends AbstractController(cc) {

  implicit val myCustomCharset = Codec.javaSupported("iso-8859-1")

  def index = Action {
    Ok(<h1>Hello World!</h1>).as(HTML)
  }

}
def HTML(implicit codec: Codec) = {
  "text/html; charset=" + codec.charset
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
There are several options for displaying 3D models on the web: 1. WebGL: This is a JavaScript API that allows you to render interactive 3D graphics in modern web browsers. It works by providing access to the graphics processing unit (GPU) of the user's device, which allows for fast rendering of 3D graphics. 2. Three.js: This is a JavaScript library that makes it easy to use WebGL to create 3D graphics on the web. It provides a simple, intuitive interface for creating and manipulating 3D objects, and it includes a wide range of built-in features and utilities for handling common tasks such as loading models and textures, animating objects, and handling user input. 3. VRML/X3D: These are file formats for representing 3D scenes and models that can be displayed in web browsers using specialized plug-ins or libraries. They have been around for a long time, but they have largely been superseded by WebGL and other more modern technologies. 4. WebVR: This is a JavaScript API that allows web developers to create VR experiences that can be accessed through VR headsets or through the web browser on a desktop or mobile device. It can be used in conjunction with WebGL or other technologies to create immersive 3D environments on the web. 5. Other options: There are also a number of other tools and technologies that can be used for displaying 3D models on the web, such as Babylon.js, A-Frame, and Cesium.js. Each of these has its own unique features and capabilities, and may be more or less suitable for different types of projects.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值