Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Rhino Server Side CGI: accessing XMPHttpRequest info

Posted on 2007-10-03
Medium Priority
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
  • 2
  • 2
  • 2
  • +1
LVL 51

Expert Comment

ID: 20021008
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

ID: 20022800
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

mreuring earned 252 total points
ID: 20030961
Look, I'll be honest, I'm a lazy bastard, but can this article (http://peter.michaux.ca/article/3001), and related source-files, maybe provide you with the information you need?
And a source that must have the information you need: http://rhinoinspring.sourceforge.net/ Although it might take a lot of digging to find it :)
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 20031987
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

ID: 20032047
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

ahoffmann earned 248 total points
ID: 20032611
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:

  import java.io.*;
  InputStreamReader stdin = new InputStreamReader(System.in);

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

Expert Comment

ID: 20432417
Forced accept.

EE Admin

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

571 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