views:

376

answers:

7

I'm aware of server-side javascript for a long time now, but I don't have a clue about how it works. Could someone point me in the right direction?

I'm interested in how to use server-side javascript + Java Servlet technology

EDIT

Great! I have seen those technologies before, but for some reason I didn't associate them with "server-side" javascript ( doh! )

Complementary question: if I want to use a javascript library to create content ( ExtJs for instance ), am I able to have a "document" to modify in the server-side as I do in the client?

( I guess I'll find out in my first attempts )

+2  A: 

ASP and ASP.NET supports server-side JavaScript. For ASP, all you do is declare:

<%@LANGUAGE=JAVASCRIPT%>

At the very top of the ASP file and you're coding in JavaScript. ASP.NET is basically the same except that you gain access to the .NET framework.

Can't help on the Java servlet front, no experience with it.

John Cavan
+3  A: 

Mozilla's Rhino JavaScript engine is pretty easy to embed; it allows subclassing of Java classes and implementing interfaces, as well as just doing some quick n' dirty JavaScript object trickery. I've been working on embedding it into GeoServer in my off moments for a couple of months now. You can take a look at both the Java code that embeds Rhino and a few JavaScript examples in our SVN repository. Rhino also has a pretty nice guide to getting started.

David Winslow
+1  A: 

"Helma is a server-side Javascript environment and web application framework for fast and efficient scripting and serving of your websites and Internet applications." - http://helma.org/

z5h
+5  A: 

Running javascript server side requires a javascript engine that can be embedded. Most of these "embeddable" engines provide an API that lets you interface between the executing javascript code and your own objects/methods. For example, you might have javascript code hooked up to allow the execution of functions written in Java or C#, or you might augment the symbol table of a script to include access to non-javascript objects in your system.

I would take a look at some of these engines, I'm guessing Rhino may be the best fit for you as its written in Java. Their tutorials outline embedding Rhino in a Java environment.

  1. A Rhino embedding tutorial: http://www.mozilla.org/rhino/tutorial.html
  2. V8 is Google's engine. V8 is not currently threadsafe, so it probably won't suit your needs in a server environment. http://code.google.com/p/v8/
  3. SpiderMonkey is the engine powering Firefox's javascript execution. It's straight C. http://www.mozilla.org/js/spidermonkey/

Edit in response to your second question.

I'm not sure exactly what you mean by content generated by a javascript library. You mention ExtJS however, which would imply HTML content I believe?. It's important to understand the difference between the DOM (which Javascript can read and modify but is not "part" of Javascript per se) and Javascript the language. If you need the idea of a DOM server side that's a different story, if you need the Javascript language then the above options should help you out.

Matt Baker
+1  A: 

I have extensive experience using server-side Javascript in a Windows environment. The Windows Scripting Host on all Windows systems provides Javascript as one of the default languages. You can create a COM object to interface with it from any language that supports COM. I think this MSDN page will get you started if you want to use this approach.

My gut feeling is that you'll be happier if you choose something that doesn't involve COM. I just wanted to make sure you had all the options in front of you.

rmeador
+1  A: 

Check out http://www.commonjs.org/

-- MV

mvalente
+1  A: 

If all you need to do is bless your HTML as Excel, you might be better served sending your HTML to the server and have it served back with a content-disposition header and the appropriate MIME type. Server-side JS doesn't normally implement a browser-like DOM so Ext isn't going to work server-side.

Alternatively you could generate your HTML serverside and skip the roundtrip. For example the POI Java library can generate real binary Excel files with multiple sheets and cell functions.

If you really want to use a server-side JS as your app server, consider Myna. I mentioned in the this question some of its advantages.

Mark Porter