I have a jsp page where certain parameter/value pairs need to be sent to one application server and a different set to another totally different server, is there a way to do that by the user pressing one submit button. And if not why not?? Wouldn't you think it is a pretty common thing to want to update say 2 databases at 2 different locations at the same time?

Thank You.

Dani AI

Generated

Short answer: an HTML form can only post to one URL, so one-click delivery to two different servers requires either (A) a server-side "fan‑out" proxy, (B) a client-side script that issues two requests, or (C) an asynchronous broker that both servers consume. Given clarified this is at the HTTP/web-app level (not direct DB commits) and pointed toward transactional solutions, the practical choices and tradeoffs are below.

A server-side proxy (recommended when both endpoints are cross-origin or need credentials) accepts the form once and forwards the data to both servers. Benefits: no CORS headaches, central logging, retries and coordinated error handling. Example (Java 11 style sketch):

String body = /* build URL-encoded body from request params */;
HttpClient client = HttpClient.newHttpClient();
HttpRequest r1 = HttpRequest.newBuilder(URI.create("https://serverA/ep"))
  .header("Content-Type","application/x-www-form-urlencoded")
  .POST(BodyPublishers.ofString(body)).build();
HttpRequest r2 = HttpRequest.newBuilder(URI.create("https://serverB/ep"))
  .header("Content-Type","application/x-www-form-urlencoded")
  .POST(BodyPublishers.ofString(body)).build();

HttpResponse<String> a = client.send(r1, BodyHandlers.ofString());
HttpResponse<String> b = client.send(r2, BodyHandlers.ofString());
// handle partial failures, retry or compensate as needed

A client-side approach uses JavaScript to post to both endpoints (parallel or sequential). This is lighter but requires both servers to allow CORS and to accept the authentication method used by the browser:

const data = new URLSearchParams(new FormData(form));
Promise.all([
  fetch('https://serverA/ep',{method:'POST',body:data}),
  fetch('https://serverB/ep',{method:'POST',body:data})
]).then(([ra,rb]) => { /* inspect ra.ok && rb.ok */ });

An async/message-queue pattern posts once to a broker; independent consumers deliver to each server and handle retries. This gives best decoupling and scalability but yields eventual consistency. Important operational notes: design endpoints to be idempotent, attach a correlation/request ID, surface partial-failure state to users, enforce TLS and input validation, and plan compensating actions if true atomicity across two independent apps is required (that requires a coordinator or explicit compensation logic).

Recommended Answers

All 2 Replies

Nothing unusual specially in financial world. Have look on Java transaction API in regards of

Nothing unusual specially in financial world. Have look on Java transaction API in regards of

Hey peter__budo thanks for the reply, however I am not asking about
communicating to the database directly. Imagine a form where you can specify 2 actions for the ACTION element in succession, that is what I need. I want to submit the form contents to 2 different web application servers with one click of the submit button. The solution does not have to be standard, I am open to hearing some creative thought over here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.