Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation

 
lanshu usav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

I have a Srting that is passed to me. I need to verify that the string passed is an object of a URLEncodedString class. I request you guys for an idea how to do it.


Thanks,
lanshu
 
Thomas Paul Bigbee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a boolean good flag

Try and create URL object with your string
if the object can be created, set the good flag to true
else catch the exception and take appropriate action.

public URL(String spec)
throws MalformedURLException


Creates a URL object from the String representation.

This constructor is equivalent to a call to the two-argument constructor with a null first argument.


Parameters:

spec - the String to parse as a URL.

Throws:

MalformedURLException - If the string specifies an unknown protocol.

See Also:

URL(java.net.URL, java.lang.String)
 
Norm Radder
Ranch Hand
Posts: 1032
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the URLEncodedString class defined?
I find something with a similiar name: java.net.URLEncoder in the 1.5 doc.


If you are asking how to detect if a String has been encoded:
You could run it thru the decode and then encode it and compare to original.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic