• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading URL

 
kevin schmidt
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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,

Kevin
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin,

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 (myserver.com) 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.

Merrill
[ February 17, 2005: Message edited by: Merrill Higginson ]
 
Stephen Huey
Ranch Hand
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're wanting to use server-side Java: J2EE
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html


You might start here to get an idea:
http://www.jsptut.com/Index.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic