• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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?
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can laugh now if you want
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear, I'll take a look at the stuff you suggest.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find HttpClient 3 easier to get started with than HttpClient 4.... just saying.
 
David Cowan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic