Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getting a inputstream in JSP  RSS feed

 
Eivind Rasmussen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am experiencing a problem when trying to post a xml document from one jsp to another.

This from the page I post (xml doc is in postParams):
URL url = new URL(serverURL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(postParams.toString());
wr.flush();

// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ( (line = rd.readLine()) != null) {
myResponse += line;
}
wr.close();
rd.close();

This is from the page that receives the document:
InputStream input = request.getInputStream();
int k;
int aBuffSize = 1024;
String StringFromWS="";
byte buff[] = new byte[aBuffSize];
OutputStream xOutputStream = new ByteArrayOutputStream(aBuffSize);

while ( (k=input.read(buff) ) != -1){
System.out.println("k2="+k);
xOutputStream.write(buff,0,k);
}
System.out.println("testing: K is "+k);


The input.read(buff) always return -1 (the buffer is empty). Why is this? I thought that request.getInputStream() always would return the entire inputstream.

Any help is deeply appiciated.

Thanks,
Eivind
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get rid of the Java scriptlet code and use JSTL instead.
Then learn to set the XML Document in the pageContext (specifically the session or request) and retrieve it from there using the JSTL x: tags.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!