cancel
Showing results for 
Search instead for 
Did you mean: 

Assign variables to URL.

Former Member
0 Kudos

Hi all,

I am working an a java application which calls a URL

I have used the code mentioned in the following link :

[http://java.sun.com/docs/books/tutorial/networking/urls/index.html]

now suppose my url is :

http://<host>/<port>/A/B/C

where the values of A,B and C vary with the incoming source payload.

Please suggest some solution

Thanks and regards,

neha

Accepted Solutions (0)

Answers (1)

Answers (1)

GabrielSagaya
Active Contributor
0 Kudos

String A="docs";

String B="books";

String C="tutorial";

URL gamelan = new URL("http", "www.java.sun.com", 80, A"/"B"/"C);

import java.net.*;

import java.io.*;

public class ParseURL {

public static void main(String[] args) throws Exception {

URL aURL = new URL("http://java.sun.com:80/docs/books/tutorial"

+ "/index.html?name=networking#DOWNLOADING");

System.out.println("protocol = " + aURL.getProtocol());

System.out.println("authority = " + aURL.getAuthority());

System.out.println("host = " + aURL.getHost());

System.out.println("port = " + aURL.getPort());

System.out.println("path = " + aURL.getPath());

System.out.println("query = " + aURL.getQuery());

System.out.println("filename = " + aURL.getFile());

System.out.println("ref = " + aURL.getRef());

}

}

Here's the output displayed by the program:

protocol = http

authority = java.sun.com:80

host = java.sun.com

port = 80

path = /docs/books/tutorial/index.html

query = name=networking

filename = /docs/books/tutorial/index.html?name=networking

ref = DOWNLOADING