Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes go to a web url using java code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "go to a web url using java code" Watch "go to a web url using java code" New topic
Author

go to a web url using java code

Paul Hankerg
Greenhorn

Joined: Jul 11, 2006
Posts: 13
Hi, I have a jsp page, and there is a button on it, when I click this button, I want to go to another url, let's say http://www.google.com. Is it possible to do it. Can one give me a clue how to implement this using Java?

I tried something like

URL link = new URL(intraURL);
HttpURLConnection httpConnect = (HttpURLConnection)link.openConnection();
httpConnect.setRequestMethod("GET");
httpConnect.setDoOutput(true);
System.out.println(httpConnect.getURL());
httpConnect.connect();

It doesn't work, I guess the above codes just makes a connection, but not physically go to the page.

any help will be apprecitaed.

thanks.
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
well you could make the button go to the page without posting to the servlet. But based on your code I assume you want the JSP to post to a servlet. If thats true take a look at sendRedirect method of HttpServletResponse.

Oh this probably belongs in JSP or Servlets.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56204
    
  13

Moved to the JSP forum.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56204
    
  13

Originally posted by Paul Hankerg:
I have a jsp page, and there is a button on it, when I click this button, I want to go to another url, let's say http://www.google.com.


Once the page is presented to the user on the client, and hence the oppurtunity to click on the button, all the Java has already executed on the server.

So the answer to your question is:



Why do you think that any Java at all is necessary?
[ October 04, 2006: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: go to a web url using java code
 
Similar Threads
Direct download Jre6
JavaFX
Need material for I/O files
How to redirect a request to another URL in Struts
How to display content of a url by using httpurlconnection?