Hi, I want to send an Image to Servlet and get the same Image back from servlet and display it. ...thats what my need is.
String url="http://localhost:8080/Kenbook/a";
GPRSConnection gprsConnection=new GPRSConnection(url);
gprsConnection.setParam("image", img.toString());
gprsConnection.start();
-----------------------------------------------------------------------------------------------------------------------------------
private void makeConnectionWithServer() {
try{
httpConnection=(HttpConnection)Connector.open(url,Connector.WRITE);
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConnection.setRequestProperty("Connection", "keep-alive");
httpConnection.setRequestProperty("Content-Length", Integer.toString(bufferOfPostParameter.toString().length()));
}catch(Exception e){
System.out.println("ERROR IN CONNECTION :"+e.getMessage());
e.printStackTrace();
}
}
private void sendDataToServer() {
try {
outputStream=httpConnection.openOutputStream();
outputStream.write(bufferOfPostParameter.toString().getBytes());
if(httpConnection.getResponseCode()!=HttpConnection.HTTP_OK){
throw new RuntimeException("SERVER NOT ACCEPTING CONNECTION :"+httpConnection.getResponseCode());
}
} catch (Exception e) {
Log("Error in Sending Data");
e.printStackTrace();
}
}
private InputStream getDataFromServer() {
try {
is=httpConnection.openInputStream();
return is;
} catch (Exception e) {
Log("Error in getting Data From Server "+e.getMessage());
e.printStackTrace();
return null;
}
}
public void run() {
try {
makeConnectionWithServer();
sendDataToServer();
InputStream is = getDataFromServer();
Form f=new Form("sss");
System.out.println("VALUE OS :"+is);
Image img=Image.createImage(is);
f.append(img);
MyFileMidlet.d.setCurrent(f);
} catch (Exception e) {
e.printStackTrace();
}
}
I am not getting the result....plz help me where i am going wrong...

Reply With Quote

