У меня есть следующий код для получения содержимого URL-адреса.
/*
* 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
Я должен иметь возможность передать переменную, и, в свою очередь, страница index.jsp вернет мне переменную, добавленную к приветственному миру, или выполнит некоторые манипуляции с переменной и отправит мне результат. Как я могу этого добиться?... Если не HttpURLConnection ..Есть ли какой-либо другой способ, с помощью которого я могу это сделать.