You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Prashanth.S" <su...@yahoo.com> on 2003/07/15 15:36:14 UTC

URL validation with struts???

Hi all,
I need to upload a resource present at a particular location by making user enter a valid URL...How can i do URL name validation using struts???Is there anything to do so??Do i need to do this in action form or action class??[what User entered is a valid url i.e,both name as well as resource present at that url)
Thanks in advance
Prashanth



---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: URL validation with struts???

Posted by Rob Leland <rl...@apache.org>.
Dichotomy wrote:

>You could definitely do that, too. If you just create a new Url(yourstringhere) it will raise that exception if it's malformed, 
>
I would encourage you to look at the implementation of URL. It does
only a small amount of validation on the format, but that may be enough,
for your case.

-Rob


>so it won't waste time creating a connection to a malformed url. I guess that's probably a better solution than the regex one, too, because it's simpler.
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: URL validation with struts???

Posted by Dichotomy <di...@greenmail.ch>.
You could definitely do that, too. If you just create a new Url(yourstringhere) it will raise that exception if it's malformed, so it won't waste time creating a connection to a malformed url. I guess that's probably a better solution than the regex one, too, because it's simpler.

-- 
If education is too expensive, try ignorance.


On Tue, 15 Jul 2003 07:03:59 -0700 (PDT)
"Prashanth.S" <su...@yahoo.com> wrote:

> Hi all,
> How abt throwing MalformedURLException in the service method inside action class??
> Than no need to do validation in action form??
> Is it correct??
> Help??
> Thanks
> Prashanth
> 
> Dichotomy <di...@greenmail.ch> wrote:
> Steps:
> 
> 1) Use a regular expression to check that the url fits the pattern you are looking for (here's a good tutorial on regexes: http://www.zvon.org/other/PerlTutorial/Output/index.html). You can do this directly with the validator framework if you're using it, or later from the action.
> 2) Open a java.io or java.nio connection to that url to check that it is valid. Look into File and/or InputStream for more info on how to do this.
> 
> You should never put any logic in the form bean itself (it should remain a plain dumb form bean). Put this code in a library and make a call to it from your action.
> 
> -- 
> If education is too expensive, try ignorance.
> 
> 
> On Tue, 15 Jul 2003 06:36:14 -0700 (PDT)
> "Prashanth.S" wrote:
> 
> > Hi all,
> > I need to upload a resource present at a particular location by making user enter a valid URL...How can i do URL name validation using struts???Is there anything to do so??Do i need to do this in action form or action class??[what User entered is a valid url i.e,both name as well as resource present at that url)
> > Thanks in advance
> > Prashanth
> > 
> > 
> > 
> > ---------------------------------
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: URL validation with struts???

Posted by "Prashanth.S" <su...@yahoo.com>.
Hi all,
How abt throwing MalformedURLException in the service method inside action class??
Than no need to do validation in action form??
Is it correct??
Help??
Thanks
Prashanth

Dichotomy <di...@greenmail.ch> wrote:
Steps:

1) Use a regular expression to check that the url fits the pattern you are looking for (here's a good tutorial on regexes: http://www.zvon.org/other/PerlTutorial/Output/index.html). You can do this directly with the validator framework if you're using it, or later from the action.
2) Open a java.io or java.nio connection to that url to check that it is valid. Look into File and/or InputStream for more info on how to do this.

You should never put any logic in the form bean itself (it should remain a plain dumb form bean). Put this code in a library and make a call to it from your action.

-- 
If education is too expensive, try ignorance.


On Tue, 15 Jul 2003 06:36:14 -0700 (PDT)
"Prashanth.S" wrote:

> Hi all,
> I need to upload a resource present at a particular location by making user enter a valid URL...How can i do URL name validation using struts???Is there anything to do so??Do i need to do this in action form or action class??[what User entered is a valid url i.e,both name as well as resource present at that url)
> Thanks in advance
> Prashanth
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: URL validation with struts???

Posted by Dichotomy <di...@greenmail.ch>.
Steps:

1) Use a regular expression to check that the url fits the pattern you are looking for (here's a good tutorial on regexes: http://www.zvon.org/other/PerlTutorial/Output/index.html). You can do this directly with the validator framework if you're using it, or later from the action.
2) Open a java.io or java.nio connection to that url to check that it is valid. Look into File and/or InputStream for more info on how to do this.

You should never put any logic in the form bean itself (it should remain a plain dumb form bean). Put this code in a library and make a call to it from your action.

-- 
If education is too expensive, try ignorance.


On Tue, 15 Jul 2003 06:36:14 -0700 (PDT)
"Prashanth.S" <su...@yahoo.com> wrote:

> Hi all,
> I need to upload a resource present at a particular location by making user enter a valid URL...How can i do URL name validation using struts???Is there anything to do so??Do i need to do this in action form or action class??[what User entered is a valid url i.e,both name as well as resource present at that url)
> Thanks in advance
> Prashanth
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: URL validation with struts???

Posted by Rob Leland <rl...@apache.org>.
Prashanth.S wrote:

>Hi all,
>I need to upload a resource present at a particular location by making user enter a valid URL...How can i do URL name validation using struts???Is there anything to do so??Do i need to do this in action form or action class??[what User entered is a valid url i.e,both name as well as resource present at that url)
>
The current commons-validator has a java class for validating a URL that 
I added,
it is pretty extensive. I still need to write the equalivent Javascript. 
Look at the unit
tests for how to use the class. Alternatively you can go to 
javascript.com to find
a standalone version for javascript. Usually when we create the 
Javascript version
it mirrors the java version so the two give the same results.

The JavaDoc on the web site is really old so look at the source:
http://cvs.apache.org/viewcvs/jakarta-commons/validator/src/share/org/apache/commons/validator/UrlValidator.java

The Unit tests:
http://cvs.apache.org/viewcvs/jakarta-commons/validator/src/test/org/apache/commons/validator/UrlTest.java

Download the nightly which has all the below plus updated javadocs
http://cvs.apache.org/builds/jakarta-commons/nightly/commons-validator/

Since method signatures have changed in commons-validator,
the easiest way to get this though is to download a *nightly* version of 
struts:(**recommended**)

http://cvs.apache.org/builds/jakarta-struts/nightly/

>Thanks in advance
>Prashanth
>
>
>
>---------------------------------
>Do you Yahoo!?
>SBC Yahoo! DSL - Now only $29.95 per month!
>  
>


RE: URL validation with struts???

Posted by Greg Hess <gh...@wrappedapps.com>.

Hi Prashanth,

I have done this using the Struts validator. I use the mask rule as
follows:

	<form name="serviceProviderForm">
	 	<field property="URL" depends="required,mask">
	 		<msg name="mask"
key="error.invalid.ServiceProviderURL"/>
			<arg0 key="serviceProvider.url"/>
			<var>
        		<var-name>mask</var-name>
        			<var-value>^http:\/\/[^ ]*$</var-value>
    			</var>
	  	</field>
	</form>

There are great examples of using the validator in the Struts
distribution. With this my code need not be concerned with the validity
of the url string and is check by the validation framework on both
client side(JavaScript) and server side and I only worry about errors
obtaining a connection to the supplied url.

Cheers,

Greg

-----Original Message-----
From: Prashanth.S [mailto:suman291857@yahoo.com] 
Sent: Tuesday, July 15, 2003 9:36 AM
To: struts-user@jakarta.apache.org
Subject: URL validation with struts???

Hi all,
I need to upload a resource present at a particular location by making
user enter a valid URL...How can i do URL name validation using
struts???Is there anything to do so??Do i need to do this in action form
or action class??[what User entered is a valid url i.e,both name as well
as resource present at that url)
Thanks in advance
Prashanth



---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org