【问题标题】:Requesting URL parameter breaks inputstream Java请求 URL 参数会中断输入流 Java
【发布时间】:2013-08-26 12:17:23
【问题描述】:

我有一个接受 POST 请求的 servlet,当我不尝试读取参数时它工作得很好。输入流包含一个解析得很好的 XML 文件。但是,当我尝试读取参数时:

String account = request.getParameter("account");

读取输入流时失败。 这怎么可能影响输入流?

【问题讨论】:

  • 您遇到的错误是什么?

标签: java servlets parameters request


【解决方案1】:

我想您正在使用 HttpServletRequest 并且来自 ServletRequest#getParameter() 文档:

If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via getInputStream() or getReader() can interfere with the execution of this method.

您在getParameter() 之前使用的是getInputStream() 还是getReader()

此处的相关答案可能会帮助您解决问题:https://stackoverflow.com/a/17129256/1524381

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-26
    • 2010-11-25
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多