How is server-side javascript used/implemented?
Asked Answered
C

7

5

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 )

Chara answered 20/10, 2009 at 21:11 Comment(2)
I think a better question is why would you want to use it?Surfacetoair
@Elizabeth: Thanks for the comment. Here's the short story: I need to serve HTML generated by a JavaScript library as application/vnd.ms-excel I've tried from the client side, but it doesn't work ( because I can only use text/html ) The complete story is here #1479520Chara
S
6

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.

Spotweld answered 20/10, 2009 at 21:23 Comment(0)
K
3

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.

Kelter answered 20/10, 2009 at 21:20 Comment(0)
T
2

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.

Toque answered 20/10, 2009 at 21:16 Comment(0)
F
1

"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/

Farrell answered 20/10, 2009 at 21:20 Comment(0)
C
1

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.

Casie answered 20/10, 2009 at 22:3 Comment(0)
M
1

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

-- MV

Multitude answered 21/10, 2009 at 9:15 Comment(0)
B
1

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.

Barby answered 31/10, 2009 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.