Originally posted by Kajol Shroff:
Hi Ashwin,
Sorry to say that but it wasnt of much help to me .. can u please help me out..i am really set on deadlines...
Please i need help.
Kajol
hi kajol,
You need to open a DataOutputStream in your applet. Send the data through this outputstream to a
servlet who in turn will will collect the data from the request object....
If the data is small then send the data with the url using the urlencode .
i hope you could use this code :
URL url;
URLConnection ucon;
String CustStr= tfCustCode.getText();
try {
url = new URL("http://90.0.0.3:8080/servlet/DataQuestServlet");
CustCode= URLEncoder.encode("Cust")+ "=" + URLEncoder.encode(CustStr) ;
ucon = url.openConnection();
ucon.setDoOutput(true);
ucon.setDoInput(true);
ucon.setUseCaches(false);
ucon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
DataOutputStream outStream = new DataOutputStream(ucon.getOutputStream());
outStream.writeBytes(CustCode);
outStream.flush();
outStream.close();
//if you want to get data from the servlet use this code
InputStreamReader inStream = new InputStreamReader(ucon.getInputStream());
int EOFile = inStream.read();
while (EOFile !=-1) {
MsgDisplay.append(String.valueOf((char)EOFile));
EOFile = inStream.read();
}
inStream.close();
} //-- try
catch (MalformedURLException me) {
System.out.println(me);
} //-- catch
catch (IOException io) {
System.out.println(io);
} //-- catch
The servlet code can be something like this :
// but you have to improvise the code
public void doPost(HttpServletRequest req, HttpServletResponse Res)throws ServletException, IOException {
Res.setContentType("text/html");
PrintWriter out = Res.getWriter();
CustCode = req.getParameter("Cust");
System.out.println("value of custcode" +CustCode);
out.println(CustCode);
}//----doGet
} //----close DataQuestServlet
Hope it helps !!
jose xavier