savannah-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-hackers] submission of Server Side JavaScript Servlets - savan


From: andymadigan
Subject: [Savannah-hackers] submission of Server Side JavaScript Servlets - savannah.gnu.org
Date: Tue, 07 Sep 2004 07:43:57 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3

A package was submitted to savannah.gnu.org
This mail was sent to address@hidden, address@hidden


Andrew Madigan <address@hidden> described the package as follows:
License: gpl
Other License: 
Package: Server Side JavaScript Servlets
System name: ssjs
Type: GNU

Description:
This project involves a way of creating servlets in JavaScript rather than 
Java. I got the idea to do this because of two reasons:
1. Neither JSP nor Servlets have any good method for separation of concerns.
2. Development time for JSP and Serlvets is slow because both most be compiled 
to class files first, and the java compiler is to slow for this to be 
acceptable on a web server.

My first solution to this was to allow for XSLT in a servlet, I did this by 
creating an abstract servlet that would perform the transform for the servlet 
that extended it. This meant that changes to the design, or any 
database-independent content could happen very quickly. This solved problem 1, 
but wasn't a perfect solution to problem 2. Note that this also still allows 
for HTML data to be sent, or even binary data.

I then discovered the Mozilla Rhino project (http://www.mozilla.org/rhino), I 
made some modifications to the XSLT setup (which also improved speed) and 
created a (concrete) servlet that performed a multi-step process to use 
javascript to generate XML.

1. A request comes in for a file, the servlet is generally mapped to *.ssjs 
(Server-Side JavaScript), the file might be called index.ssjs.
2. index.ssjs is actually an XML file, containing instructions for the servlet 
telling it which XSLT stylesheets to use, and which script to execute.
3. The script must contain a getContentType() method, which specifies which (of 
several previously specified stylesheets) the servlet is to use, the method is 
passed the request object for this purpose.
4. doGet or doPost is called in the script, note that three parameters are 
passed: request,response, and the writer to write to (if the content type 
sepecified matches no stylesheet, this is request.getWriter(), otherwise it's a 
PipedWriter). This function is expected to generate XML.
5. While the XML is being generated, a DOM is built, this DOM is transformed to 
the output.

This solved problem 2 because Rhino, while still creating classes, executes 
faster than any java compiler could even dream of. This also had the added 
benefit that many web developers know at least some JavaScript.

Two enhancements are planned: 
1. A nicer binding to the servlet api, currently it relies on Rhino's ability 
to work with Java Classes. I plan to make the interface more JavaScript-like. 
(e.g. request.parameters["key"] should return the value of that parameter. 
2. JSD (named to avoid confusion w/ JSP) meaning JavaScript documents. This 
would allow the use of pseudo-tags in XML to create the XML. This would add a 
step of translation to JavaScript before it could be executed. This wouldn't be 
intended to act like JSP, but it would allow for a great amount of developer 
control. I already have simple parser for parsing pseudo tags and sending them 
to handler, I also have a handler for translation to JavaScript. The parser 
follows the general idea of SAX.

I will be posting the source code as it stands at www.geocities.com/andymadigan 
momentarily (probably before you see this.) Note that the sources do not yet 
have GPL notices on them. They will be put in later.   

Note: I have already tested this project because I actually used for a sumemer 
job (no dev of this code was on the company's payroll, I wrote it because when 
I wrote a demo for the proposal, it took so long I decided I needed a better 
way of doing it. I had already been thinking about it, this just got me going.)



Other Software Required:
This is a java project. The dependencies are as follows: 
-Mozilla Rhino (NPL/GPL)
-JAXP (aelfred is used, so this must be GNU JAXP, see note below)
-A Servlet Container (I am currently trying to make it work in paperclips, it 
works perfectly in tomcat) Tomcat is Apache though, so I obviously want this to 
work with a GPL'd container.
-Everything listed above is available in SableVM, and can also be compiled 
using GCJ.

Note that while one goal of this project is to ame it work perfectly on a Free 
OS, I also don't want to make a java project that can't work in a non-free OS, 
or that might be hard to make GPL. Since I can't seem to get GNU JAXP's XSLT 
support to work under windows, future versions may use James Clark's XT (I am 
beginning changes now, I have already tested (and modified) XT for this 
purpose) at least until GNU JAXP is truly cross-platform. XT is under the MIT 
license.

Other Comments:



_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/







reply via email to

[Prev in Thread] Current Thread [Next in Thread]