JSP 上的 2 个请求,第二个请求删除变量内容
2 requests on JSP second one deletes variables contents
我在 JSP 页面上收到 2 个请求,然后我在 Util class 中处理数据。但是我怎样才能保留第一个请求的数据呢?似乎第二个请求删除了我保存在 vars 中的第一个请求的所有内容。
请求由我的 orbeon 进程中的 2 个不同的 send() 发出。
以下是我希望在 JSP 上保存数据的方式:
// read request parameters
String documentId = request.getParameter("document");
String pdfUrl = "";
String base64Data = "";
// read request content (XML data entered by the user)
String data = Utils.readRequestBody(request);
if (Utils.isUrl(data)) {
pdfUrl = Utils.getUrl(data);
} else {
base64Data = Utils.encodeb64(data);
}
这是我在 Utils class 中的方法:
public static boolean isUrl(String data) {
boolean isUrl = false;
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
if (data.toLowerCase().contains(urlString.toLowerCase())) {
isUrl = true;
}
return isUrl;
}
public static String getUrl(String data) {
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
data = data.substring(urlString.length(), data.length()-7);
return data;
}
public static String readRequestBody(HttpServletRequest req) throws IOException {
StringBuilder sb = new StringBuilder();
String line = null;
BufferedReader reader = req.getReader();
while ((line = reader.readLine()) != null) {
// important to add lineSeparator to preserve line feeds in multiline text fields
sb.append(line).append(System.lineSeparator());
}
return sb.toString();
}
public static String encodeb64(String s) {
return new String(Base64.getEncoder().encode(s.getBytes()));
}
所以我想我有什么不明白所以我需要帮助来学习如何处理这个案例。
此致,
约瑟夫
我只需要在 JSP 中创建 HttpSession 即可使其正常工作。感谢@Jacek Cz 的提醒。
我在 JSP 页面上收到 2 个请求,然后我在 Util class 中处理数据。但是我怎样才能保留第一个请求的数据呢?似乎第二个请求删除了我保存在 vars 中的第一个请求的所有内容。
请求由我的 orbeon 进程中的 2 个不同的 send() 发出。
以下是我希望在 JSP 上保存数据的方式:
// read request parameters
String documentId = request.getParameter("document");
String pdfUrl = "";
String base64Data = "";
// read request content (XML data entered by the user)
String data = Utils.readRequestBody(request);
if (Utils.isUrl(data)) {
pdfUrl = Utils.getUrl(data);
} else {
base64Data = Utils.encodeb64(data);
}
这是我在 Utils class 中的方法:
public static boolean isUrl(String data) {
boolean isUrl = false;
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
if (data.toLowerCase().contains(urlString.toLowerCase())) {
isUrl = true;
}
return isUrl;
}
public static String getUrl(String data) {
String urlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><uri>";
data = data.substring(urlString.length(), data.length()-7);
return data;
}
public static String readRequestBody(HttpServletRequest req) throws IOException {
StringBuilder sb = new StringBuilder();
String line = null;
BufferedReader reader = req.getReader();
while ((line = reader.readLine()) != null) {
// important to add lineSeparator to preserve line feeds in multiline text fields
sb.append(line).append(System.lineSeparator());
}
return sb.toString();
}
public static String encodeb64(String s) {
return new String(Base64.getEncoder().encode(s.getBytes()));
}
所以我想我有什么不明白所以我需要帮助来学习如何处理这个案例。
此致,
约瑟夫
我只需要在 JSP 中创建 HttpSession 即可使其正常工作。感谢@Jacek Cz 的提醒。