简体   繁体   English

是否可以使用AJAX将表单发布到Java Servlet并重定向?

[英]Its possible to POST a form with AJAX to java servlet and redirect?

I explain my problem: 我解释我的问题:

I have one JSP webpage and I have one AJAX call that send some data to one servlet. 我有一个JSP网页,并且有一个AJAX调用,它将一些数据发送到一个servlet。

The servlet that receive the data have to send this data and more other information to an external URL. 接收数据的servlet必须将此数据和更多其他信息发送到外部URL。 This external URL have to be load in the screen with the POST params sent. 必须使用发送的POST参数在屏幕中加载此外部URL。

Its possible to do this with AJAX and JAVA? 是否可以使用AJAX和JAVA做到这一点?

I know that the easy way is send a normal FORM from MYPAGE to this external website (without the servlet) and the form automatic redirects to this external URL, but I dont have all the data, so I need one intermediate servlet to get it... 我知道简单的方法是将普通表单从MYPAGE发送到该外部网站(没有servlet),并且表单会自动重定向到该外部URL,但是我没有所有数据,因此我需要一个中间的servlet来获取它。 ..

The schema: 模式:

MYPAGE -- (AJAX request to one servlet)---> MY SERVLET ---(POST to an URL with params)---> EXTERNALWEBSITE MYPAGE-(对一个servlet的AJAX请求)-> MY SERVLET ---(POST到带参数的URL)-> EXTERNALWEBSITE

The user have to see in the screen the EXTERNALWEBSITE like if the call would be direct between MYPAGE and the EXTERNALWEBSITE 用户必须在屏幕上看到EXTERNALWEBSITE,就像调用是否直接在MYPAGE和EXTERNALWEBSITE之间一样

You could send the additional data that you need in the response of your Ajax call. 您可以在Ajax调用的响应中发送所需的其他数据。 Then on the client-side, right after your Ajax call, you can do a jQuery.post() to the external URL that will include all the data. 然后在客户端上,就在您的Ajax调用之后,您可以对包含所有数据的外部URL进行jQuery.post()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM