【发布时间】:2015-08-08 02:48:49
【问题描述】:
所以我正在尝试自学后端开发并使用 Google App Engine 来帮助我。
我的问题是: HTTP Servlet 和 API 方法有什么区别?
他们似乎为我做同样的事情。 让我们使用一个应用程序的示例,您在客户端上做简短的笔记并将它们发送到服务器进行处理:
@ApiMethod(httpMethod = "POST")
public final String sendShortNote(@Named("note") final String note) throws ServiceException {
// Do POSTlike things here
}
并设置一个 HTTPServlet 来处理 doPost 并从正文中检索注释:
public class NoteServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.getParameter("note");
//continue to do things and return a response.
}
据我所知,Servlet 允许我向 HTTP 正文添加内容,而 ApiMethod 只是将参数添加为查询 url,这使得 Servlet 更安全?
此外,Servlet 允许我通过响应返回多个值,而 APIMethod 只允许我返回单个值。
这些正确吗?
【问题讨论】:
标签: java google-app-engine servlets