aspose file tools*
The moose likes Servlets and the fly likes URL Connection Servlet help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL Connection Servlet help" Watch "URL Connection Servlet help" New topic
Author

URL Connection Servlet help

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I am trying to get my servlet to read the info it gets sent when a resource (html, jsp, servlet)
I got a jsp page and a servlet. The jsp page has this code in it:

String hello = "HELLO";
URL url = new URL("http://127.0.0.1/vp");
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("Content-Type", "text/xml");
urlc.setDoOutput(true);
urlc.setDoInput(true);
PrintWriter pw = new PrintWriter(urlc.getOutputStream());
pw.println(hello);
pw.flush();
pw.close();
The servlet:
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
System.out.println("!!!" +
BufferedReader dis = new BufferedReader(new InputStreamReader(req.getInputStream()));
String theData = "";
String s;
while ((s = dis.readLine()) != null)
{
theData += s;
}

dis.close();
System.out.println("-theData:\n" + theData);
}
}
The theData variable does not print out anything. What am I doing wrong?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL Connection Servlet help