File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL Connection Servlet help" Watch "URL Connection Servlet help" New topic

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("");
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("Content-Type", "text/xml");
PrintWriter pw = new PrintWriter(urlc.getOutputStream());
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;

System.out.println("-theData:\n" + theData);
The theData variable does not print out anything. What am I doing wrong?
It is sorta covered in the JavaRanch Style Guide.
subject: URL Connection Servlet help
Similar Threads
a big problem
FTP Socket Programming
How to call servlet do post method from a pojo
show any www
How Do I Forward/Redirect Extra Parameters From JSP To ASP via POST?