• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display URL in browser

 
Satish Labhala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Satish Labhala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is displaying the url as string if i use pl, but i want it to be displayed as hyperlink.
 
Kapil Mishra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Satish Labhala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to servlets in lieu of any environmental information.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic