File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Reading URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading URL" Watch "Reading URL" New topic

Reading URL

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85

I'm writing a program for my work and I have run into a bit of a problem. I need to read a URL to retrieve some parameters that I am passing in it. I know that I can read them with javascript, but I want to read the url with Java. Is there anyway of reading this string with Java 1.3? The server that our portal sits on only supports Java 1.3.

Thanks and regards,

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

It would help to know where the code is that you want to use to read a URL. Is it in a JSP file? in a servlet? When you say "read a URL", do you mean get the URL that was sent by a browser to your servlet? Or do you want to forward to another URL?

If the code you are writing is in a servlet or JSP, you can get it with a combination of request.getServerName(), request.getServletPath() and request.getQueryString() where request is a variable pointing to the HTTPServletRequest that was passed to you by the web container. getServerName gives you the first part of the url ( and getServletPath() give you the second part (/myApplication/myServlet) and getQueryString() gives you the parameters passed (?parm1=abc&parm2=def)

If you simply wish to look at a parameter passed to you, the best way is to use request.getParamter("parm1") or request.getParameters("parm1") if you expect more than one value in "parm1". The first returns a String, and the second returns a String array.

[ February 17, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
You're wanting to use server-side Java: J2EE

You might start here to get an idea:
I agree. Here's the link:
subject: Reading URL
It's not a secret anymore!