servlets - servlet 中的响应映射

标签 servlets ember.js

响应映射在 Servlet 中如何工作?

每个响应如何知道清除特定 HTML 或 Handlebars 上的输出?

最佳答案

有一个 ember-java带有 Jersey REST 服务

的 github 项目

它使用扩展 HttpServletcom.sun.jersey.spi.container.servlet.ServletContainer。它使用 ServletResponse 返回输出写入正文并调用 flush()

getOutputStream .. Calling flush() on the ServletOutputStream commits the response. Either this method or getWriter() may be called to write the body

如果您检查 servlet 中的特定服务,它会返回 json 响应 (@Produces)

@Produces(MediaType.APPLICATION_JSON)
public Customers get(@QueryParam("ids[]") List<Long> ids) {
    if (ids != null && !ids.isEmpty()) {
        return new Customers(manager.findByIds(ids));
    }
    return new Customers(manager.findAll());
}

Ember 是使用适配器连接到 HTTP 服务器

The store uses an object called an adapter to know how to communicate over the network. By default, the store will use DS.RESTAdapter, an adapter that communicates with an HTTP server by transmitting JSON via XHR

ember-data.js有适配器配置

DS.RESTAdapter = DS.Adapter.extend({ ...

它返回在 router.js 中定义的 Customers

App.Router.map(function() { this.resource("customers"); this.resource("customer", { path: '/customer/:customer_id' });

并在 customer.hbs 中有客户模板

关于servlets - servlet 中的响应映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47785902/

相关文章:

dynamic - Router如何处理动态内容?

ember.js - 多个 ember js 应用程序?

Java使用byte[]下载文件

java - Spring中Service层的作用是什么?在这种情况下我如何拆分我的逻辑?

servlets - Jetty 过滤器修改响应 - java.lang.IllegalStateException : WRITER

ember.js - 观察数组属性

java - 如何将多个WAR文件打包到一个Maven项目中?

java.lang.NoClassDefFoundError : javax/servlet/http/HttpServletRequest 错误

ember.js - 如何在 Ember.js 中禁用弃用警告?

javascript - "Not" Handlebars 模板内的运算符(operator)