Take the 2-minute tour ×

In PHP/Apache I can get the full url and cut it up into parts like this

URL: example.com/friends/enemies-cats/

Then using PHP explode function I can split the URL by the "/" into an array.

Array[0] = 'friends';
Array[1] = 'enemies-cats';

I wonder, is it possible to do the same thing on a Java server. I am hoping the same thing could work on all servers e.g. tomcat, jboss, websphere etc. I would prefer not to use things like urlrewriter if I can avoid it.

Also is it possible to achieve the same thing in ASP?

Realistically, I would like to find the easiest way to convert the URL to an array in each of PHP, JSP, and ASP.

If it is possible, any idea where to start? Any limitations? Any security issues, etc.?

share|improve this question
JSP and ASP are view technologies backed by respectively Java and C++/C# programming language. When looking for answers on this kind of questions which are completely unrelated to the presentation layer, you should look in the Java or C++/C# corners respectively, not in JSP/ASP. In Java for example, splitting a String is quite easy if you know to find the java.lang.String API: java.sun.com/javase/6/docs/api/java/lang/String.html –  BalusC Feb 10 '10 at 11:50
Cool, really appreciate this answer. Im a bit new to this but hopefully will pick it up quick. –  Ke. Feb 11 '10 at 17:15
add comment

1 Answer

up vote 0 down vote accepted


String[] stringArray = url.split("/"); 

PHP: You already have it...


ASP: I don't know ASP, but here is what google found:

parts = Split(url, "/");
share|improve this answer
Thanks this really gives me some direction. Just out of interest if its as easy as this, why does java urlrewriter exist because urlrewriter seems a bit overkill for such a simple operation, no? –  Ke. Feb 10 '10 at 5:31
add comment

Your Answer


