• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display URL in browser

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to servlets in lieu of any environmental information.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic