javax.servlet.http.HttpServlet.doPost()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(278)

本文整理了Java中javax.servlet.http.HttpServlet.doPost()方法的一些代码示例,展示了HttpServlet.doPost()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpServlet.doPost()方法的具体详情如下:
包路径:javax.servlet.http.HttpServlet
类名称:HttpServlet
方法名:doPost

HttpServlet.doPost介绍

[英]Called by the server (via the service method) to allow a servlet to handle a POST request. The HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is useful when posting information such as credit card numbers.

When overriding this method, read the request data, write the response headers, get the response's writer or output stream object, and finally, write the response data. It's best to include content type and encoding. When using a PrintWriter object to return the response, set the content type before accessing the PrintWriter object.

The servlet container must write the headers before committing the response, because in HTTP the headers must be sent before the response body.

Where possible, set the Content-Length header (with the javax.servlet.ServletResponse#setContentLength method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.

When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.

This method does not need to be either safe or idempotent. Operations requested through POST can have side effects for which the user can be held accountable, for example, updating stored data or buying items online.

If the HTTP POST request is incorrectly formatted, doPost returns an HTTP "Bad Request" message.
[中]由服务器调用(通过service方法),以允许servlet处理POST请求。HTTP POST方法允许客户端一次性向Web服务器发送长度不限的数据,在发布信用卡号码等信息时非常有用。
重写此方法时,读取请求数据,写入响应头,获取响应的writer或output stream对象,最后写入响应数据。最好包括内容类型和编码。使用PrintWriter对象返回响应时,请在访问PrintWriter对象之前设置内容类型。
servlet容器必须在提交响应之前写入头,因为在HTTP中,头必须在响应主体之前发送。
在可能的情况下,设置内容长度头(使用javax.servlet.ServletResponse#setContentLength方法),以允许servlet容器使用持久连接将其响应返回给客户端,从而提高性能。如果整个响应适合响应缓冲区,则会自动设置内容长度。
当使用HTTP 1.1分块编码(这意味着响应具有传输编码头)时,不要设置内容长度头。
此方法不需要是安全的或幂等的。通过POST请求的操作可能会产生副作用,用户需要对此负责,例如,更新存储的数据或在线购买物品。
如果HTTP POST请求的格式不正确,doPost将返回HTTP“错误请求”消息。

代码示例

代码示例来源:origin: voldemort/voldemort

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  super.doPost(req, resp);
  String storeName = req.getParameter("store");
  String key = req.getParameter("key");
  String keyType = req.getParameter("key_type");
  String value = req.getParameter("value");
  String action = req.getParameter("action");
  Object keyObj = parseKey(keyType, key);
  Map<String, Object> params = new HashMap<String, Object>();
  StoreClient<?, ?> client = clientFactory.getStoreClient(storeName);
  engine.render("query.vm", params, resp.getOutputStream());
}

代码示例来源:origin: javax.servlet/servlet-api

doPost(req, resp);

代码示例来源:origin: org.apache.geronimo.specs/geronimo-servlet_3.0_spec

doPost(req, resp);

代码示例来源:origin: org.jboss.spec.javax.servlet/jboss-servlet-api_3.0_spec

doPost(req, resp);

代码示例来源:origin: org.openrdf/sesame

protected void _doPost(
  HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException
{
  super.doPost(request, response);
}

代码示例来源:origin: errai/errai

@Override
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 super.doPost(req, resp);
}

代码示例来源:origin: org.jboss.as/jboss-as-websockets

@Override
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 super.doPost(req, resp);
}

代码示例来源:origin: com.github.houbb/mvc-core

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  super.doPost(req, resp);
}

代码示例来源:origin: mikebrock/jboss-websockets

@Override
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 super.doPost(req, resp);
}

代码示例来源:origin: com.atlassian.oauth/atlassian-oauth-shared

protected void doRestrictedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  super.doPost(req, resp);
}

代码示例来源:origin: com.ebmwebsourcing.geasywebeditor/webeditor-service

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  
  try {
    execute(req, resp);
  } catch (Exception e) {
    e.printStackTrace();
  }
  
  super.doPost(req, resp);
}

代码示例来源:origin: com.ebmwebsourcing.petalsbpm/petalsbpm-utils

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  
  try {
    execute(req, resp);
  } catch (Exception e) {
    e.printStackTrace();
  }
  
  super.doPost(req, resp);
}

代码示例来源:origin: de.ruedigermoeller/kontraktor-http

protected void nonAPIPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  Log.Warn(this,"unhandled post "+req.getPathInfo());
  super.doPost(req,resp);
}

代码示例来源:origin: com.helger/ph-webscopes

/**
 * Implement HTTP POST
 *
 * @param aHttpRequest
 *        The original HTTP request. Never <code>null</code>.
 * @param aHttpResponse
 *        The original HTTP response. Never <code>null</code>.
 * @param aRequestScope
 *        The request scope to be used. Never <code>null</code>.
 * @throws ServletException
 *         In case of an error.
 * @throws IOException
 *         In case of an error.
 */
@OverrideOnDemand
protected void onPost (@Nonnull final HttpServletRequest aHttpRequest,
            @Nonnull final HttpServletResponse aHttpResponse,
            @Nonnull final IRequestWebScope aRequestScope) throws ServletException, IOException
{
 super.doPost (aHttpRequest, aHttpResponse);
}

代码示例来源:origin: yangfuhai/jboot

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  /*
   * Where a servlet has received a POST request we still require the capability to include static content.
   */
  switch (req.getDispatcherType()) {
    case INCLUDE:
    case FORWARD:
    case ERROR:
      doGet(req, resp);
      break;
    default:
      super.doPost(req, resp);
  }
}

代码示例来源:origin: org.jvnet.hudson.winstone/winstone

doHead(request, response);
} else if (method.equals(METHOD_POST))
  doPost(request, response);
else if (method.equals(METHOD_PUT))
  doPut(request, response);

代码示例来源:origin: io.undertow/undertow-servlet

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  if(allowPost) {
    doGet(req, resp);
  } else {
    /*
     * Where a servlet has received a POST request we still require the capability to include static content.
     */
    switch (req.getDispatcherType()) {
      case INCLUDE:
      case FORWARD:
      case ERROR:
        doGet(req, resp);
        break;
      default:
        super.doPost(req, resp);
    }
  }
}

代码示例来源:origin: javax/javaee-web-api

doPost(req, resp);

代码示例来源:origin: org.apache.openejb/javaee-api

doPost(req, resp);

代码示例来源:origin: bozaro/git-as-svn

super.doPost(req, resp);
} catch (FileNotFoundException inored) {
 log.warn("Event repository not exists: " + event.getProjectId());

相关文章