wood burning stoves*
The moose likes Servlets and the fly likes Waiting for page loading and get title of the page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Waiting for page loading and get title of the page" Watch "Waiting for page loading and get title of the page" New topic
Author

Waiting for page loading and get title of the page

Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
Hi to all,
I need to get a parameter who's inside the title of a web page. I am using servlets and java. How can I do? I suppose I should wait for the page to load too.

Many thanks!
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Just Curious, why would you want that parameter?


Regards, Prasad
SCJP 5 (93%)
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
Because of this: http://code.google.com/intl/it-IT/apis/accounts/docs/OAuth2InstalledApp.html Look under the section "Choosing a redirect URI"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

What do you mean by a "parameter in the title"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

By seeing the link, i guess, you want the authorization code, in the same link, in Handling the response section, they say, authorization code is passed as code, getting this field is not going to help you?
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
You ask google for an authorization code and google will provide you one embedded in the title of the page. You should save it and send it again to google together with other parameters to get an access token.

Authorization code is passed as code when you send it to Google. I think that this phrase in that link leaves no doubts: "The authorization code can be returned to your application in the title bar of the browser or to an http://localhost port in the query string."
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm confused by the phrase "I need to get".

You can easily see the page title by looking at the top of the browser. But apparently you want to "get" the value in some other way?
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
Oh sorry, I need to acquire it with my application without user intervention.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Be very very very precise about what you mean by the "title of the page". The only thing I can take that to mean is the text in the <title> tags, and that makes no sense whatsoever.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Marco Zanini wrote:Oh sorry, I need to acquire it with my application without user intervention.


I'm still baffled. There's a web page somewhere (you didn't say where). And you have an application which I suppose must be running, although you didn't say where. Except that you're using servlets, which I suppose means it's a web application. And I suppose there must be some relationship between this application and the web page, but you haven't said anything about how that relationship is established.
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
So, I have to be sorry again, many times one thinks things are well explained but it's wrong.

So I have an application running on a web server on my machine. I want to obtain access to google services using oAuth. So I have to make a request to the Google server with some parameters and read the parameter in the response which is embedded in the title of the page. This is because for authoriing the application the user is redirected to an url that asks him for permissions and then Google redirects the browser to the webpage which title I have to examine.

I hope now everything is clear, thank you for your patience.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Marco Zanini wrote:So I have an application running on a web server on my machine. I want to obtain access to google services using oAuth. So I have to make a request to the Google server with some parameters and read the parameter in the response which is embedded in the title of the page.


So your servlet should send a request to this Google URL, and then parse the response with an HTML parser in order to extract the <title> element. Something like Apache HttpClient might help, although a plain old URLConnection might work just fine if the request is a GET request. And if the HTML returned is simple enough, you might even be able to just extract the data from the <title> element using plain old string processing.

This is because for authoriing the application the user is redirected to an url that asks him for permissions and then Google redirects the browser to the webpage which title I have to examine.


Am I correct in assuming that what you describe here is a process which you are automating? So instead of the user going to the Google URL and entering the permission information, you want your application to do that instead? If so then probably the process I described there isn't the way to do it. I found a variety of tutorials with names like "OAuth for Web Applications" which seem to me to describe what you should be doing, and scraping the response for <title> elements didn't seem to feature in those tutorials.
 
jQuery in Action, 2nd edition
 
subject: Waiting for page loading and get title of the page
 
Similar Threads
Where is the rest of this thread?
Change the language in IE title Bar
Variable inside title tag
Page Title ignored in maven site
tree like select list (html)