J
Juan Pardillos
Hi everybody,
I trying to call a .jsp page from Java, but no success for the moment.
The code I'm using is:
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.io.*;
public class MyClass {
public static void download(InputStream in, File file) throws
IOException {
System.out.println("Creating output file");
FileOutputStream out = new FileOutputStream(file);
byte[] b = new byte[1024];
int len;
while((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
System.out.println("Created output file");
}
public static void main(String[] args) throws IOException {
URL url = new URL("PutHereTheURL");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setFollowRedirects(false);
connection.connect();
// Send the data
String postString = "option1=" + ;
DataOutputStream dos = new DataOutputStream(
connection.getOutputStream() );
dos.writeBytes(postString);
dos.close();
// Read the resulting data from the Post
InputStream is = connection.getInputStream();
download(is, new File("myFile.html"));
connection.disconnect();
}
}
But the html page that I obtain as a result is the initial page
corresponding to the input form. What I want is to submit that input
form with value "valueOfOption1" for the input choice "option1".
Any ideas of what can be the problem?
Thanks in advance
I trying to call a .jsp page from Java, but no success for the moment.
The code I'm using is:
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.io.*;
public class MyClass {
public static void download(InputStream in, File file) throws
IOException {
System.out.println("Creating output file");
FileOutputStream out = new FileOutputStream(file);
byte[] b = new byte[1024];
int len;
while((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
System.out.println("Created output file");
}
public static void main(String[] args) throws IOException {
URL url = new URL("PutHereTheURL");
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setFollowRedirects(false);
connection.connect();
// Send the data
String postString = "option1=" + ;
DataOutputStream dos = new DataOutputStream(
connection.getOutputStream() );
dos.writeBytes(postString);
dos.close();
// Read the resulting data from the Post
InputStream is = connection.getInputStream();
download(is, new File("myFile.html"));
connection.disconnect();
}
}
But the html page that I obtain as a result is the initial page
corresponding to the input form. What I want is to submit that input
form with value "valueOfOption1" for the input choice "option1".
Any ideas of what can be the problem?
Thanks in advance