DoPost correctly activated but request = null !??! help!

Hi there,
I'm coding a client in j2me, learning from books like Core J2ME. Its been going fine but i've hit a snag, i can select the method to doPost fine servlet side - my problem is the request seems to be null when this is done. The client also calls the doGet method which functions perfectly.
The whole point of the doPost method is for me to send a message -with a few characters that wouldnt be appropriate for a URL request style (i.e. full stops -basically im sending messages).
i've beeen Reading the examples and trying to get the code working but still no joy... the code i have is below for each method:
first method from the client:
// send a POST request to Web server
     public void sendMessage() throws IOException
     HttpConnection hc = null;
     DataInputStream dis = null;
     DataOutputStream dos = null;
     String message = "";
     // the request body
     String requeststring = "u="+userDetails+"&m="+compose.getString()+"&t="+recipient.getString()+"&a=st";
     try
     // an HttpConnection with both read and write access
     hc = (HttpConnection)
     Connector.open(URLIP, Connector.READ_WRITE);
     // set the request method to POST
     hc.setRequestMethod(HttpConnection.POST);
     // obtain DataOutputStream for sending the request string
     dos = hc.openDataOutputStream();
     byte[] request_body = requeststring.getBytes();
     // send request string to Web server
     for (int i = 0; i < request_body.length; i++) {
     dos.writeByte(request_body);
     // flush it out
     dos.flush();
     // obtain DataInputStream for receiving server responses
     dis = new DataInputStream(hc.openInputStream());
     // retrieve the responses from Web server
     int ch;
     while ((ch = dis.read()) != -1) {
     message = message + (char) ch;
     } finally {
     // free up i/o streams and http connection
     if (hc != null) hc.close();
     if (dis != null) dis.close();
     if (dos != null) dos.close();
     System.out.println(message);
the servlet doPost Code
public void doPost (HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
          String name = "";
String value = "";
// parse out the value pair from the POST body
// the expected string is "request=gettimestamp"
try {
BufferedReader br = request.getReader();
String line;
String requeststring = "";
System.out.println(request.getQueryString());
while (( line = br.readLine()) != null)
requeststring = requeststring + line;
StringTokenizer sTokenizer =
new StringTokenizer(requeststring, "=");
if (sTokenizer.hasMoreTokens())
name = (String) sTokenizer.nextToken();
if (sTokenizer.hasMoreTokens())
value = (String) sTokenizer.nextToken();
} catch (Exception e) {
System.err.println(e);
// turn auto flush on
PrintWriter out =
new PrintWriter(response.getOutputStream(), true);
response.setContentType("text/html");
String message = "ok";
response.setContentLength(message.length());
out.println(message);

Here's a method that I've used to successfully POST to a servlet:
     * Sends a POST request to the servlet, putting the given String into the contents.
     * @param String containing the request contents.
     * @return InputStream to receive messages from the servlet.
     * @exception IOException if anything goes wrong with the communication.
    public InputStream sendPostMessage(String contents) throws IOException
        URLConnection connection = this.servletURL.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        // Write the contents as POST data
        DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
        String encodedContents = URLEncoder.encode(contents, DEFAULT_ENCODING);
        dos.writeBytes("message=" + encodedContents);
        dos.flush();
        dos.close();
        return connection.getInputStream();
    } I'd also recommend that you write an echo servlet or JSP that you can send a GET or POST request to and have the echo just send the result back. It'll help you make sure that what you send is arriving and all the connections are okay.
See if this helps you.
%

Similar Messages

Maybe you are looking for

  • I would like to know how to add images and create a slide show

    The image I try to add to my web page show up as grayed out boxes and never show up. I would also love to learn how to make a slide show to enhance my home page. Thank you!

  • Export PDF in Captivate 5 and Publishing CP4 project in CP5

    When I publish flash (swf) videos in CP4, I always tick the "Export PDF" option to also get the PDF version - and then offer the PDFs for download as an alternative to watching online (or send them via e-mail). I have learned to live with the fact th

  • JClient Component Demo - not compatible with 9.0.3 (?)

    I try to load the JClient Component Demo from OTN using th README supplied, and I have several problems: 1. The README says to unzip the JClientBindingDemo directly into mywork, AND indicates that a DIRECTORY with the same name will be created. This

  • Creating LOV  in Table Action.

    Hi, Can we create a LOV in table action ,if yes then is LOV Action button is the only way of achieving that.As lot of issue are there if i use LOV action instead of LOV as no criteria item is present in LOV action button. Thanks

  • Extract Data from Essbase to Oracle

    We have a requirement of extracting data from Essbase and loading the same into Oracle Need to know what are the possible ways of doing it and which is the best one. Are there any ODBC drivers, api's that come with Hyperion Essbase server installatio