简体   繁体   中英

Handling Post Requests

yesterday i started brainstorm for a project of mine and I'm not sure if its the correct approach. On my website I'm having an (kind of an order form) which sends a post to a target URL, which works with a simple curl php script. The target is an external service (where I have no access no rights, nothing). I only know that I will get a POST with further processed data back from the service, which I have to save into my DB.

in steps:

  1. Users fills out the (order) form and posts data to an external url on my website.

  2. data gets externally handled and after finishing that resents a post.

  3. read incoming post data.

  4. save data into DB.

  5. Success page on my website.

My thoughts were to handle the incoming data with a servlet (spring maven project) but I'm not sure if this is a correct approach. Is there a better why to do this. Or is the first step with the php scripts wrong. thx for any help.

A simplest workflow could be 1. Forward the initial (Order form with values) request to a servlet 2. Invoke a post request using java to an external url inside this servlet (Using Apache http client, or libraries such as HTMLUnit) 3. Once you get the incoming response in your servlet, you can update your database.

If you are using spring, the controller could forward initial request to a business class which will handle this post processing and delegate the database update to respective DAO.

There are a number of suitable ways to handle this, and the decision is largely a matter of preference and what you're familiar with. Spring can handle this sort of job quite well.

Note: Maven is a build system for Java and some other JVM languages. I recommend using it, but it's not part of Spring; what you're probably looking for is Spring MVC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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