响应映射在 Servlet 中如何工作?
每个响应如何知道清除特定 HTML 或 Handlebars 上的输出?
最佳答案
有一个 ember-java带有 Jersey REST 服务
它使用扩展 HttpServlet
的 com.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/