Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

URL Connection Servlet help  RSS feed

Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!