aspose file tools*
The moose likes Servlets and the fly likes Display URL in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display URL in browser" Watch "Display URL in browser" New topic
Author

Display URL in browser

Satish Labhala
Greenhorn

Joined: Sep 13, 2005
Posts: 5
I have to display an URL in login page when user enters incorrect password. The URL would take the users to some other screen where they can change the password, if they want to.

I am using the following code. But its not working.
String pl = "https://passwordchange.com/";
try {

//some other code;
URL url = new URL(pl);
}
catch(NamingException ex) {
//this exception would be triggered when user enters incorrect password.
throw new NotValidException("Invalid password or account is locked. Follow the link to change password.\n" + url.getContent());
}
catch(MalformedURLException mue) {
// I KNOW THAT URL IS CONSTANT AND VALID..SO I DON'T WANT TO WRITE ANYTHING HERE.
}

This code is saying that url is not resolved in the Exception. How do i display the url as hyperlink in browser when the user enters a wrong password.
Please let me know how to proceed.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Satish Labhala wrote:This code is saying that url is not resolved in the Exception.

It's right. You defined the URL inside the try/catch block. How about logging "pl" (the string) rather than the URL?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Satish Labhala
Greenhorn

Joined: Sep 13, 2005
Posts: 5
It is displaying the url as string if i use pl, but i want it to be displayed as hyperlink.
Kapil Mishra
Greenhorn

Joined: Oct 04, 2009
Posts: 25
you can display hyperlink in browser by following way:-

<a href="http://passwordchange.com">Change your Password</a>

but I am not getting what logic you have used there ?? I think using of try/catch blocks would be on next page.

SCJP 5,SCWCD 5
Satish Labhala
Greenhorn

Joined: Sep 13, 2005
Posts: 5
I know that we can display hyperlinks using tags in html. But in my requirement, i have to display a hyperlink whenever user enters incorrect password. The exception NamingException is used to catch incorrect password.
I would like to know how to display hyperlink in addition to message while throwing NotValidException.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

You haven't said anything about the context. Is this a command-line application? A GUI application? A web application? Some kind of server?

And what do you mean by "display a URL"? When that happens, what will the user see and where will he or she see it?
Satish Labhala
Greenhorn

Joined: Sep 13, 2005
Posts: 5
It is a web application. We have a Login.jsp page, where in we enter credentials. But the authentication happens in some other server. So we would be calling a java program from this jsp and the program itself would return the message such as incorrect password, if the user enters wrong password. Now instead of the message 'incorrect password', i should throw a message saying 'incorrect password. please visit https://passchange.com to change your password'. In this message, i would like have the url https://passchange.com as hyperlink so that the user can click on it when he/she wishes to change the password.

I hope i am clear. The bottom line is how do we display hyperlink such as http://google.com using java program.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

You just send a response which is HTML containing the appropriate URL. You already said you know what the HTML looks like, so there shouldn't be any problem doing that.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moving to servlets in lieu of any environmental information.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40058
    
  28
Welcome to JavaRanch


I think this thread would fit better on another forum. Moving.

Oh, I see you have already been moved
Satish Labhala
Greenhorn

Joined: Sep 13, 2005
Posts: 5
I nailed it down. Its very simple. Actually i thought too much about it and forgot the basic fact that browser can automatically detect html tags. Its working fine. Thanks all for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display URL in browser