Rhino Server Side CGI: accessing XMPHttpRequest info

Posted on 2007-10-03
Last Modified: 2013-12-25
I have Rhino/JavaScript working on a Mac using the Apache server.
Using an XMLHttpRequest in my client script causes my server side
JavaScript to run. If you're curious, it looks like this:

#!/usr/bin/java -classpath js.jar
print("Content-type: text/plain");
print("Hello World<br>");

This works fine.

My XMLHttpRequest uses the POST method and sets the variables to be
posted in .send.

How do I modify the above script to see these variables?
Question by:ghenne
    LVL 51

    Expert Comment

    you have to import a proper java class with importPackage() and use the methods from there, or you need to read and parse <STDIN> yourself

    Author Comment

    While this suggests a couple of ways to do this, it does not answer the question "How do I modify the script to see these variables?"
    LVL 17

    Accepted Solution

    Look, I'll be honest, I'm a lazy bastard, but can this article (, and related source-files, maybe provide you with the information you need?
    And a source that must have the information you need: Although it might take a lot of digging to find it :)

    Author Comment

    Hi mreuring,

    Thanks for the reply. Peter's website was a big help in part of what I needed to do, but he hadn't gotten to the CGI post part.

    I actually figured out a working solution - it's not elegant, but works well enough for my purposes:

    I'll leave the question open a bit longer in the hope that a more elegant solution can be suggested.
    LVL 17

    Expert Comment

    Hmmm, but combining that particular solution with ahoffman's remakr about parsing STDIN, make me wonder. What is on STDIN when your javascript is running? Is that perhaps where the whole request ends up? If so, that should allow you to parse it, or find the proper Java class to do so for you.

    See, the problem for me is, I don't exactly understand how your js-file gets called (if I were to be running some js, based on requests coming in, I'd wrap it in a servlet-container...). Could you explain more about the rest of the setup perhaps? That way I could run some test on my mac and see if I can puzzle it out...
    LVL 51

    Assisted Solution

    The solution suggested in the groups link is a workaround: the perl script parses the POST data (STDIN) and passes them as GET data (command line arguments here) to Rhino/JavaScript where there exists the "arguments" object to collect the parameters.

    In java (as I suggested earlier) you use something like:

      InputStreamReader stdin = new InputStreamReader(;

    There're more (sophisticated) classes like BufferedReader() or Scanner(), but I guess you have to do it the hard way byte by byte ...
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn how to count occurrences of each item in an array.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now