我需要使用一些参数调用我的第三方网站 (MoneyPayment)。我只需要使用 JSP 和 Servlet。我正在尝试提交表单,我正在调用我正在尝试的 Servlet:
pRequest.setAttribute("gatewayparam",vGateparam);
pRequest.setAttribute("checksum", vChecksum);
RequestDispatcher dispatcher = pRequest.getRequestDispatcher("https://MoneyPaymentURL");
try {
dispatcher.forward( pRequest, pResponse );
} catch (IOException e) {
log.info("IOException-: "+e);
}
这给了我 FileNotFoundException:
java.io.FileNotFoundException: SRVE0190E: File not found: /ProjectName/https:/MoneyPaymentURL
我也尝试使用 send.redirect(URL) 但在这种情况下如何传递参数?
请有人建议我如何继续前进。
最佳答案
为了从 Servlet 重定向到第三方 URL,您应该使用 response.sendRedirect("theURL")
- 您可以将 URL 中的参数作为 queryString 传递
- 示例:
response.sendRedirect("theURL?paramName=paramValue")
- 这不会是隐藏参数,将在网址栏中可见
- 示例:
- 您可以将参数设置为
session
属性- 示例:
session.setAttribute("paramName", "参数值");
response.sendRedirect("theURL");
- 获取 JSP 中的 session 属性
out.println(session.getAttribute("paramName").toString());
session.removeAttribute("paramName");
- 示例:
希望这能解决您的问题。
关于java - 如何使用一些隐藏参数从 Servlet 重定向到第三方 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40734023/