954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

URL Validation

Hi All
I want to validate the format of file path using struts.That is if the user gives c/:Test.txt instead of c:\Test.txt.PLz Help.
Thank you

grajeshmsc
Newbie Poster
13 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Just use StringTokenizer and look for the /. If found replace it with the one you want.

Regards,
Techy

techy
Newbie Poster
18 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

There's nothing wrong with either path...
And what about other operating systems?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

why would you allow the user to enter the path anyway?(not that it's a bad thing) Why can't you use a file browser?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

You should always allow manual entry as well.
It works a LOT faster if the user knows what he wants to enter.

But I'd not validate paths at all. The client is solely responsible for that, all the server should do is gracefully handle the situation in which the file doesn't exist.

And NEVER let the user enter a path and/or filename existing on the server and have the server do something with that file. That's a massive breach of security.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Maybe I don't understand the context. Wouldn't it be better in many ways to have a browse button(say the user wants to upload something) even if he/she does know the URL?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

yes, having a button as an optional way to fill the file location is fine.
But you should not require the use of that button by not providing an input field for manual entry.
Pressing a button, launching a popup, filling the location in that, clicking another button, that's 4 steps to fill the file location.
Just filling it directly is a single step, far faster.

Maybe not that important on a hobby site where people may use it once a month or so, but on a professional intranet application where it's used by many people many times a day it becomes first a major annoyance and then reason for the application to require changing to improve performance.

Also, one should never rely solely on clientside validation (which forcing the user to select an option from a popup dialog effectively is), as someone will come who circumvents that in some way.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Okay, that makes more sense. So basicly it comes down to the popups "blowing up" in the users face, which I've always tried to avoid. I guess you could have both validations as an option to suit both sides of things. Thanks for the help.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

I'm a little confused here. Lets say this is an upload page were the user enters the path or clicks the browse button, whichever he/she prefers. How exactly do you get that file off their computer since there is so many restrictions with java?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

HI
Thankz for your replies. Actually we r developing an Intranet application in which the user should specify the resource files and the result files folder which is in the server.So i need a validation to validate the entered file path is correct and available. Now i got another solution.tht is
/* to hold the file path */
StringBuffer localSBFilePath = new StringBuffer( File.separator);
/* to hold the boolean value for long term files folder exists */
boolean localIsLongTermFolderExists = false;
/* to hold the long term files folder */
String localLongTermFilesFolder = null;
/* to hold the FILE */
File localFile = null;
/* get the long term files folder */
localLongTermFilesFolder = PrimaryServerAdminPKForm.getPServerStorage();// Here PrimaryServerAdminPKForm is an form bean using Struts.
/* append the file path*/
localSBFilePath.append(localLongTermFilesFolder);
localFile = new File(localSBFilePath.toString());
/* check the folder exists in the given path */
localIsLongTermFolderExists = localFile.isDirectory();
/* if not throw exception */
if (!(localIsLongTermFolderExists))
{
throw new AppsCustomException("error.PrimaryServerAdminPKForm.primaryserver.FileNotFound");
}


Thankz for all
cheers mite
Rajesh G.

I'm a little confused here. Lets say this is an upload page were the user enters the path or clicks the browse button, whichever he/she prefers. How exactly do you get that file off their computer since there is so many restrictions with java?
grajeshmsc
Newbie Poster
13 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

You don't get anything ;)
As we're talking web applications here the browser gets the file and sends it as a datastream in the HTTP request.
The server can then parse that stream into a byte array (for example) and write it out to disk.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Sorry, Actually my problem is i have to just validate the file path format entered by the user, as the files are available in the server.Say the user should specify the result files folder,Long term file folder which is available in the server.So in this case i have to validate the path entered by the user is valid or not.Thank you for spending your time for mine.
Cheers mite
Rajesh G.
You don't get anything ;)
As we're talking web applications here the browser gets the file and sends it as a datastream in the HTTP request.
The server can then parse that stream into a byte array (for example) and write it out to disk.

grajeshmsc
Newbie Poster
13 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Possibly use a regular expression? I stink at writing them, so I can't help you do that, but I'm sure there's some method in some class that will let you verify a string against a regular expression.

mmiikkee12
Posting Whiz in Training
274 posts since Oct 2004
Reputation Points: 17
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You