W3C home > Mailing lists > Public > www-lib@w3.org > July to September 2001

doPost problem

From: Mihai Dobrescu <michi@alphatech2000.com>
Date: Thu, 02 Aug 2001 18:01:40 +0300
Message-ID: <3B696B54.2050005@alphatech2000.com>
To: www-lib@w3.org


   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.

           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
               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)
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");
    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);
    f ree(data);
    if (status == YES)
        HTPrint("Post succeeded.\n");
    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));

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 
Looking up localhost.localdomain
Contacting localhost.localdomain
Post succeeded.
doPost() initiated.
Writing 1Kbytes
[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

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:54 UTC