Forums Register Login

Using JSP to post data to external url without losing control focus

+Pie Number of slices to send: Send
Hi Everyone,

I have a little problem I am hoping someone can help me with please. I need to use a JSP to "POST" a block of text to an external web page, this must not be done using params, it needs to be a plain text payload. The target url will provide no response and hence I need my jsp to post the data to the external url but then keep processing within the jsp. This would work using a <c:import> with params but I cannot use the params, it must be a post of a block of text. If I could have used a POST Method on <c:import> I would not have any problem. Any suggestions anyone please?

Thanks in advance.
+Pie Number of slices to send: Send
A JSP is a phenomenally and spectacularly poor choice of where to try to do something like this. Why not from a servlet where the classes in java.net (or 3rd party tools like HttpClient) would make this relatively straightforward?
+Pie Number of slices to send: Send
Cheers Bear, for that optimistic prognosis, I know it should be done in a servlet, but does that mean it is impossible to do from a JSP?
+Pie Number of slices to send: Send


Only if you party like it's 1999 and put Java code in the form of scriptlets in your JSP.

Is there any reason that you feel the need to do this in a JSP rather than its controller?
+Pie Number of slices to send: Send
Well Bear, where do I start .... my limited Java capacity (I'm an old mainframe C programmer who is still retraining ;) ), my lack of a setup Java compile environment having just switched to a new Apple Mac and worst of all I just need a temporary fix while I re-design this properly.
+Pie Number of slices to send: Send
you can laugh now if you want
+Pie Number of slices to send: Send
Is the situation that you've inherited some legacy web app code with JSPs already written the "old way", with Java code embedded? Since you mentioned the JSTL (<c:import>), I assumed modern standards were being used.

If legacy code, then yeah, a refactor just to add some new functionality isn't called for. But in new code (or legacy code that's so bad that not refactoring prevents any forward progress), JSPs and web app should be written using modern constructs and standards.

But, by all that's good, if your app is already using modern standards, you should not introduce antiquated practices like scriptlets into the JSPs.

In any case, there are no JSP mechanisms to generate a POST request that's not form-generated. You can use the aforementioned java.net package, or a tool such as HttpClient.
+Pie Number of slices to send: Send
Thanks Bear, I'll take a look at the stuff you suggest.
+Pie Number of slices to send: Send
I find HttpClient 3 easier to get started with than HttpClient 4.... just saying.
+Pie Number of slices to send: Send
Bear - Quick Follow-up

I have moved to using httpclient as you suggested. I went straight to v4 with it being on GA, to save moving again later. However, in my "newness" to this I cannot see how you POST just a plain old text string?!? I can see how to send name/value pairs (which is not what I want) and I can see how to send a file stream ( which is not what I want) but no plain old post this string as body text. Can you steer me in the right direction please?

Thanks in advance for the help
+Pie Number of slices to send: Send
To be honest, I have no information for you because I'm still using HttpClient 3. I was going to update a month or so ago, and found the new layout just too confusing to bother upgrading just for the sake of it.

As this has specifically become about HttpClient, I've moved it along to the open source forum where hopefully someone savvy about HttpClient 4 can help you out.
+Pie Number of slices to send: Send
Maybe check out creating your own HttpRequestWriter, but I'm not convinced twisting HttpCore to do what you're looking for is the best answer--I'd probably explore other libraries first to see if there's an easier way.
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2383 times.
Similar Threads
Using c:import with JSF deferred expression
Exception -- Content is not allowed in prolog
problem while importing output of the URL in JSP using JSTL
c:import with Facelets
Reading xml data in JSP
Thread Boost feature
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:39:59.