doPost problem

   Hello.

   I have the following problem:

   I have followed the post.c example in order to submit in a C function 
a string received from COBOL, through a POST method, to a servlet on a 
HTTP server. I don't know whether I should use the WWW_FORM instead of 
the WWW_PLAINTEXT format, but either way I do not receive a pair 
`parameter=value` in the doPost method of the servlet, where I attempt 
to retrieve it through a request.getParameter () call.

   I have tried to trace the query string using the 
request.getQueryString() method. However, it returns null and I presume 
it is natural in case of the POST method, while it should have been 
non-null in case of a GET method. I have found mail messages on the 
Internet from people who also got null from a getQueryString() method in 
a similar situation.

   Please be so kind as to look over the code below and at least tell me 
which is the general error that I make. Thank you.



This is the COBOL program.



       special-names.
           call-convention 0 is cdecl-convention-val.
       data division.
       working-storage section.
       01 work-areas.
           03 wa-string  pic x(30) value "COBOLstring" & x"00".
       01 ws-return-code pic 999   comp-5 value 127.
       procedure division.
       entry-point section.
               call cdecl-convention-val "post_display"
                       using     wa-string
                       returning ws-return-code
               end-call
               stop run.



This is the C function.




#include "WWWLib.h"
#include "WWWInit.h"
#include <string.h>
#include <stdlib.h>
#define POSTHOST "http://localhost.localdomain:8080/mssj/postd"
extern int post_display (const char *pic_x);
PRIVATE int printer (const char *fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}
PRIVATE int tracer (const char *fmt, va_list pArgs)
{
    return (vfprintf(stderr, fmt, pArgs));
}
PRIVATE int terminate_handler (HTRequest  *request, HTResponse 
*response, void *param, int status)
{
    HTRequest_delete(request);
    HTProfile_delete();
    exit(0);
}
int post_display (pic_x)
const char *pic_x;
{
    HTRequest      *request      = NULL;
    HTParentAnchor *src          = NULL;
    HTAnchor       *dst          = NULL;
    char           *dst_str      = NULL;
    char           *data         = NULL;
    char           *cwd          = NULL;
    BOOL            status       = NO;
    HTProfile_newNoCacheClient("libwww-POST", "1.0");
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
    dst_str = (char *)malloc(strlen(POSTHOST)+1);
    if (dst_str == NULL) return -1;
    strcpy(dst_str, POSTHOST);
    data = (char *)malloc(strlen("pic_x=")+strlen(pic_x)+1);
    if (data == NULL) return -1;
    strcpy(data, "pic_x=");
    strcat(data, pic_x);
    cwd = HTGetCurrentDirectoryURL();
    HTPrint("Posting to \"%s\" data \"%s\"\n", dst_str, data);
    request = HTRequest_new();
    dst = HTAnchor_findAddress(dst_str);
    src = HTTmpAnchor(NULL);
    HTAnchor_setDocument(src, data);
    HTAnchor_setFormat(src, WWW_PLAINTEXT);
    HTAnchor_setLength(src, strlen(data));
    status = HTPostAnchor(src, dst, request);
    HT_FREE(cwd);
    free(dst_str);
    f ree(data);
    if (status == YES)
    {
        HTPrint("Post succeeded.\n");
        HTEventList_loop(request);
    }
    return 0;
}



This is the Java servlet.



import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PostDisplay extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException, ServletException
    {
        System.out.println("doGet() not implemented.");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse 
response) throws IOException, ServletException
    {
        System.out.println("doPost() initiated.");
        Enumeration e = request.getParameterNames();
        while (e.hasMoreElements())
        {
            String paramName  = new String((String)e.nextElement());
            String paramValue = new String(request.getParameter(paramName));
            System.out.println(paramName+"="+paramValue);
        }
    }
}




And this is the output:



[root@localhost LibWWW]# make
rm -f adsamp adsamp.int adsamp.idy adsamp.o post_display.o *~ core
gcc -c -o post_display.o `libwww-config --cflags` post_display.c
cob -x -a adsamp.cbl post_display.o `libwww-config --libs`
[root@localhost LibWWW]# adsamp
Posting to "http://localhost.localdomain:8080/mssj/postd" data 
"pic_x=COBOLstring"
Looking up localhost.localdomain
Contacting localhost.localdomain
Post succeeded.
doPost() initiated.
Writing 1Kbytes
Reading...
[root@localhost LibWWW]#



(Why doesn't the servlet print pic_x=COBOLstring in the 
System.out.println() call?)

Received on Thursday, 2 August 2001 10:58:20 UTC