need help on servlet: How to send post method from servlet?

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
I'm trying to make a servlet do post to a webform.

The servlet does some work and then I need it to send the results to a webform, however, I don't want to use the get method.

Any help would be appreciated.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
^bump

I want to POST the results, since I don't want to recreate the entire html again in the servlet. I'll probably use asp to retrieve the post information unless something else can retrieve it.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Interesting question. I think this doesn't really have anything to do with servlets (of course you may do it from a servlet) because you are acting as a client instead of a server.

I would take a look at java.net.URLConnection and java.net.HttpURLConnection. It looks like you create an instance with URL.openConnection. If you use an http url I guess you'll get an instance of HttpURLConnection back. Then you can do whatever you need with it. It doesn't matter if you use POST or GET, it has nothing to do with html. What matters is how the webform expects the data to come in.

Why do you want to do this? Usually the reason would be connecting to a service that is offered by some other entity. But you're talking about writing the webform yourself? Why even break this over http if you don't have to?
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Originally posted by: kamper
Interesting question. I think this doesn't really have anything to do with servlets (of course you may do it from a servlet) because you are acting as a client instead of a server.

I would take a look at java.net.URLConnection and java.net.HttpURLConnection. It looks like you create an instance with URL.openConnection. If you use an http url I guess you'll get an instance of HttpURLConnection back. Then you can do whatever you need with it. It doesn't matter if you use POST or GET, it has nothing to do with html. What matters is how the webform expects the data to come in.

Why do you want to do this? Usually the reason would be connecting to a service that is offered by some other entity. But you're talking about writing the webform yourself? Why even break this over http if you don't have to?

I'm using the servlet to authenticate with a service and then forward the user (as well as email info from the auth) to another webform. I figured the simpliest way to accomplish this is to POST/GET that information to the webform. On the webform, I'm using ASP to retrieve the information.

I can send the resulting info through to the webform by appending it to the end of the URL, but I'd prefer not to do it that way. A POST would be better since the user can't manipulate the results or go back to the same page without authentication first.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
I figured out how to do it, after a some googling. However, now I don't know I would open the page after I POST the information. All the examples I've seen are for POSTing to a cgi or some server which will return results. However, I want to POST to an ASP page that displays the results in HTML.