wood burning stoves 2.0*
The moose likes Servlets and the fly likes URLConnection question, Posting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "URLConnection question, Posting " Watch "URLConnection question, Posting " New topic
Author

URLConnection question, Posting

B Wiley Snyder
Ranch Hand

Joined: Nov 26, 2003
Posts: 50
Hello, I'm using the code below to post to an address using URLConnection.

But I need it to show up in the address area. I can't send a doGet request and I was wondering if there was a work around or something that would just change the URL to the actual URL it is posting to.



Thanks in advance
B Wiley Snyder
Ranch Hand

Joined: Nov 26, 2003
Posts: 50
Okay, I cannot seem to get an answer for this question. Is it a stupid question? If so, if you could explain why it is that would be great.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
I don't understand this part of your problem:
But I need it to show up in the address area.


It looks like you want the servlet to handle a GET request by opening a connection to another site and doing a POST. Is that right?
If so, what is actually happening when you try it?

On the other hand, if you are trying to send the user's browser to another URL, that is the response sendRedirect method, which can only do a GET.
Bill


Java Resources at www.wbrogden.com
B Wiley Snyder
Ranch Hand

Joined: Nov 26, 2003
Posts: 50
Originally posted by William Brogden:
I don't understand this part of your problem:


It looks like you want the servlet to handle a GET request by opening a connection to another site and doing a POST. Is that right?
If so, what is actually happening when you try it?

On the other hand, if you are trying to send the user's browser to another URL, that is the response sendRedirect method, which can only do a GET.
Bill


I just want this url URL theUrl = new URL("https://foo.foo.com/getPost");
in the address area. That is where it is going anyway but it is stuck in the servlet calling post. So, when I go to localhost:8080/ThisServlet(ThisServlet being the code above. It posts and gets a response from foo.foo.com but the address stays localhost:8080/ThisServlet like it is supposed to do. I want to put foo.foo.com in the address area without posting it. Can I re-write it somehow or am I just stuck with get, I'm sure I probably have to do it with get.

The reason I am doing this:
I have site A, not secure(http) posts info to site B(https). I wanted https to show up in the URL so it does not look like it is not a secure site. I wanted to use post becuase I wanted to pass a session variable to site B. Which I cannot pass a session variable from one domain to another in my situation.

I'm sure I'll just use doGet() and load the variables that way instead of post, I just thought it might be possible to do it the other way....

thanks

B Wiley Snyder
Ranch Hand

Joined: Nov 26, 2003
Posts: 50
basically I used two forms on my page and it solved my problems. Never even thought of the simplest way....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLConnection question, Posting
 
Similar Threads
closing streams
Connection in servlets
Streaming Video Through a Servlet (.wmp)
Accessing servlets using URLConnection
Servlets example