0

我遇到了一些设计和编码问题。第 1 步:我收到一个 http post 请求,我将其保存到我的数据库中。2:那么我需要重新发送相同的请求。3:返回外部url的形式。带有重定向到 target_URL 的简单 jsp 端(我认为这很不方便,但我不知道该怎么做。

我的问题是我正在向我重定向我的应用程序用户的 url 发送一个 http post 请求。什么是更好的解决方案。我应该用我的jsp发送它吗?但我怎样才能在那里获取我的数据。问题#2:我发送帖子请求的方式是否正确?感谢您的帮助,我今天有点迷路或受阻;)

@RequestMapping("/internalData")
    public String paymentReceiveInternal(HttpServletRequest request)
            throws ServletException, IOException {

User user = new User();
user.setUserName(request.getParamter("name");

//save user into DB

// resend the request.
URL targetUrl = new URL(VIEW_TARGET_URL);
HttpURLConnection connection = (HttpURLConnection) targetUrl.openConnection();
connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects(false);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(request.getContentLength()));

OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(urlParameters);
writer.flush();
writer.close();
connection.disconnect();

return VIEW_TARGET_URL;
4

0 回答 0