gpt4 book ai didi

当给定 jsession id 时,Java Applet 似乎使用旧的响应对象

转载 作者:行者123 更新时间:2023-11-30 04:32:43 25 4
gpt4 key购买 nike

我的 jsf 页面中有一个文件上传小程序。该小程序需要一个可以发送 POST 请求的地址。 (我无法编辑此帖子请求以添加更多字段或其他内容)。然后我的 servlet 的 post 方法存储该文件。这项工作无法由托管 bean 完成,因为 servlet 必须使用 @MultiPartConfig 进行注释,而我无法将此注释添加到 jsf 托管 bean 中。为了强制上传小程序使用相同的 session ,我根据此 topic 在 post 请求中添加了一个名为 jsessionId 的 URL 属性。 。现在,每当我尝试在 session 期间上传多个文件时,小程序都会停止并显示错误消息“在响应正文中未找到正则表达式字符串“^SUCCESS$””,这是因为小程序需要在 servlet 响应中使用此字符串以便知道上传成功。

当我查看小程序的调试代码时,响应包含大量 html 代码,但不包含此成功字符串,尽管我将其添加到了 Servlet 代码中。这是我的 servlet 的代码:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.reset();
if (!userBean.getUploadedDatasets().isEmpty()) {
String datasetID = userBean.getUploadedDatasets().getLast().replaceAll("/", "%2F");
response.sendRedirect(response.encodeRedirectURL("http://____________/faces/details.xhtml?id="+datasetID));
}
}

/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response){
PrintWriter out = null;
try {
Part filePart = request.getPart("item");
InputStream filecontent = filePart.getInputStream();
String datasetID = repBean.persistDataset(filecontent, uploadBean.getFolder());
userBean.getUploadedDatasets().add(datasetID);
out = response.getWriter();
out.println("SUCCESS");
} catch (ServletException ex) {
Logger.getLogger(RequestHandler.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(RequestHandler.class.getName()).log(Level.SEVERE, null, ex);
}finally{
out.close();
}
}

doGet方法被小程序用作afterUploadURL(因此这是文件上传后跳转到的url)

小程序代码是:

          <APPLET
CODE="wjhk.jupload2.JUploadApplet"
NAME="JUpload"
ARCHIVE="wjhk.jupload.jar"
WIDTH="640"
HEIGHT="300"
MAYSCRIPT="true"
ALT="The java pugin must be installed.">
<param name="postURL" value="http://________________/request;jsessionid=#{session.id}" />
<!-- Optionnal, see code comments -->
<param name="showLogWindow" value="false" />
<param name="debugLevel" value="99" />
<param name="httpUploadParameterName" value="item" />
<param name="nbFilesPerRequest" value="1" />
<param name="httpUploadParameterType" value="oneFile" />
<param name="afterUploadURL" value="http://________________/request" />
</APPLET>

尝试上传第二个文件后,“旧”(我就是这么想的,但我对 servlet 还不够了解)响应如下所示:http://pastebin.ca/2300999(字符太多,所以我必须上传到那里)

最佳答案

您的问题是由于 servlet 正在发送 GET(隐含的 HEAD)请求上的重定向而引起的。日志的以下部分包含相关信息:

00064   13:44:42.482      HttpProtocolFinderThread     [DEBUG]      Getting serverProtocol from HEAD request
00065 13:44:42.485 HttpProtocolFinderThread [DEBUG] Checking protocol with URL: http://___________________:8080/application1/request;jsessionid=47440f88e532021656b3724eea33
00066 13:44:42.501 HttpProtocolFinderThread [DEBUG] [initByteArrayEncoder] proxy=DIRECT, proxy.type=DIRECT, useProxy=false, url.host=___________________, url.port=8080
00067 13:44:42.501 HttpProtocolFinderThread [DEBUG] [onAppendHeader] Start
00068 13:44:42.502 HttpProtocolFinderThread [DEBUG] [onAppendHeader] Header appended; Cookie: __utma=132868616.170774110.1354796930.1356109339.1356547898.3; __utmz=132868616.1356547898.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
00069 13:44:42.509 HttpProtocolFinderThread [DEBUG] [onAppendHeader] Header appended; User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
00070 13:44:42.510 HttpProtocolFinderThread [DEBUG] [onAppendHeader] End
00071 13:44:42.510 HttpProtocolFinderThread [DEBUG] [HTTPConnectionHelper append]
00072 13:44:42.511 HttpProtocolFinderThread [DEBUG] Before sendRequest()
00073 13:44:42.511 HttpProtocolFinderThread [DEBUG] Using non SSL socket, direct connection
00074 13:44:42.538 HttpProtocolFinderThread [DEBUG] After sendRequest()
00075 13:44:42.538 HttpProtocolFinderThread [DEBUG] -------------------------------------------------------------------------
00076 13:44:42.538 HttpProtocolFinderThread [DEBUG] ----------------- HEAD message sent (start) --------------------------
00077 13:44:42.539 HttpProtocolFinderThread [DEBUG] -------------------------------------------------------------------------
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] HEAD /application1/request;jsessionid=47440f88e532021656b3724eea33 HTTP/1.1
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] Host: ___________________:8080
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] Accept: */*
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] Accept-Encoding: identity
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] Connection: close
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] Cookie: __utma=132868616.170774110.1354796930.1356109339.1356547898.3; __utmz=132868616.1356547898.3.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG] User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20100101 Firefox/16.0
00078 13:44:42.539 HttpProtocolFinderThread [DEBUG]
00079 13:44:42.539 HttpProtocolFinderThread [DEBUG] -------------------------------------------------------------------------
00080 13:44:42.540 HttpProtocolFinderThread [DEBUG] ----------------- HEAD message sent (end) -----------------------------
00081 13:44:42.540 HttpProtocolFinderThread [DEBUG] -------------------------------------------------------------------------
00082 13:44:42.548 HttpProtocolFinderThread [DEBUG] -------- Response Headers Start --------
00083 13:44:42.556 HttpProtocolFinderThread [DEBUG] HTTP/1.1 302 Moved Temporarily
00084 13:44:42.558 HttpProtocolFinderThread [DEBUG] Location: http://___________________:8080/application1/faces/details.xhtml;jsessionid=47440f88e532021656b3724eea33?id=%2F37ded64f-f2c9-4b90-99ea-79c34eb140e5
00085 13:44:42.559 HttpProtocolFinderThread [DEBUG] Content-Type: text/html;charset=ISO-8859-1
00086 13:44:42.566 HttpProtocolFinderThread [DEBUG] Content-Language: de-DE
00087 13:44:42.578 HttpProtocolFinderThread [DEBUG] Content-Length: 306
00088 13:44:42.578 HttpProtocolFinderThread [DEBUG] Date: Thu, 10 Jan 2013 12:44:42 GMT
00089 13:44:42.579 HttpProtocolFinderThread [DEBUG] Connection: close
00090 13:44:42.579 HttpProtocolFinderThread [DEBUG]
00091 13:44:42.580 HttpProtocolFinderThread [DEBUG] --------- Response Headers End ---------
00092 13:44:42.580 HttpProtocolFinderThread [DEBUG] This is a HEAD request: we don't care about the bytearrayResponseBody
00093 13:44:42.584 HttpProtocolFinderThread [DEBUG] HEAD status: 302
00094 13:44:42.585 HttpProtocolFinderThread [DEBUG] HEAD protocol: HTTP/1.1
00095 13:44:42.586 HttpProtocolFinderThread [DEBUG] Location read: http://___________________:8080/application1/faces/details.xhtml;jsessionid=47440f88e532021656b3724eea33?id=%2F37ded64f-f2c9-4b90-99ea-79c34eb140e5
00096 13:44:42.594 HttpProtocolFinderThread [INFO] postURL switched from http://___________________:8080/application1/request;jsessionid=47440f88e532021656b3724eea33 to http://___________________:8080/application1/faces/details.xhtml;jsessionid=47440f88e532021656b3724eea33?id=%2F37ded64f-f2c9-4b90-99ea-79c34eb140e5

小程序基本上通过 HEAD 请求测试 postURL 的可用性,一旦确定它已被重定向,它就会使用重定向的 URL 作为新的 postURL (根据复制粘贴日志的最后一行)。然而,重定向的 URL 指向一个 JSF 页面,该页面返回一大堆 HTML。

您需要修复您的 doGet() ,使其不执行重定向,或者添加一个实际上不返回任何内容的 doHead() 。由于 HEAD 根据 HTTP 规范基本上是一个没有响应正文的 GET,因此默认的 doHead() 实现委托(delegate)给 doGet() 并丢弃响应正文。重写 doHead() 应防止其委托(delegate)给 doGet()

关于当给定 jsession id 时,Java Applet 似乎使用旧的响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14258745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com