Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

HttpURLConnection

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i want to submit a simple form using threading.
URL cellUrl = new URL("http://192.168.123.41:8080/a/servlet/Form");
HttpURLConnection conn = (HttpURLConnection) cellUrl.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream dos = new DataOutputStream (conn.getOutputStream ());
dos.writeBytes (strData);
dos.flush ();
dos.close ();
i am using this code but it is not.and what is problem with my code.
it do not submit any data to form.the code of form is given below and it is present in get method of servlet and data is submit on the post method of same servlet.i want to submit my data into post method using HttpURLConnection.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CreateFile extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res) {
try {
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<form method=post>");
out.println("<input type=text name=x>");
out.println("<input type=submit>");
out.println("</form>");
}
catch(IOException ex){System.out.println("Error "+ex);}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) {

try{ System.out.println("Creating File");
FileOutputStream file=new FileOutputStream("String.txt");
DataOutputStream dos=new DataOutputStream(file);
dos.writeBytes(req.getParameter("x"));
file.close();

}
catch(IOException ex){System.out.println("Error "+ex);}
}
}
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic