У меня есть следующий код, чтобы получить содержимое URL ..Как передать переменную с HttpURLConnection
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
/**
*
* @author Ravi
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
HttpURLConnection connection = null;
OutputStreamWriter wr = null;
BufferedReader rd = null;
StringBuilder sb = null;
String line = null;
URL serverAddress = null;
try {
serverAddress = new URL("http://192.16.110.11:8084/RaviTest/index.jsp?id=3");
//set up out communications stuff
connection = null;
//Set up the initial connection
connection = (HttpURLConnection)serverAddress.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();
//get the output stream writer and write the output to the server
//not needed in this example
//wr = new OutputStreamWriter(connection.getOutputStream());
//wr.write("");
//wr.flush();
//read the result from the server
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sb = new StringBuilder();
while ((line = rd.readLine()) != null)
{
sb.append(line + '\n');
}
System.out.println(sb.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
//close the connection, set all objects to null
connection.disconnect();
rd = null;
sb = null;
wr = null;
connection = null;
}
}
}
Но этот код только копирует содержимое указанного URL.
Вместо если я хочу подключиться к странице JSP и я могу получить значения, которые посылаются на этой странице JSP динамически ...
Например, если у меня есть страница http://192.16.110.51/WelcomeProject/index.jsp
I Should быть в состоянии передать переменную, и, в свою очередь, страница index.jsp передаст мне обратно переменную, добавленную с помощью мира hello, или сделайте некоторые манипуляции с переменной и отправьте мне результат. Как я могу достичь этого? ... Если не HttpURLConnection .. Есть ли другой способ, с помощью которого я могу это сделать.
Вы имеете в виду, как веб-сервис? –