• Post Reply Bookmark Topic Watch Topic
  • New Topic

javaScript in Servlets ?

 
Nikita Deshmukh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can u use javaScript in Servlets ? How ??

Nikita
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can but OH MAN does it create a nightmare of code!

First off ANY time you can seperate your backend code and your front end display its well worth taking the time! That way if you have a major design change you arent spending days, weeks and months trying to redo all your servlets and how they present the data!

I always recommend using external styles for formatting and external script files for any javascript you may need. Saves a lot of headaches!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet simply creates a text buffer that gets sent to the browser. There's nothing to prevent you from including Javascript, HTML or the Gettysburg Address in that text.

Even this person "u", whoever that is, can do it.

But generally, formatting an HTML page (including any Javascript) is best performed in a JSP rather than maintaining markup built up in string buffers.
[ July 28, 2005: Message edited by: Bear Bibeault ]
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikita,

You can use the javascript in servlets.

Write your js code in seperate editor and then put complete js code in out.println("YOUR JS CODE");
But you have to carefull since you may have to use many escape characters etc..
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternate interpretation of the original post would be execution of Javascript on the server side. Server-side Javascript is possible - the "Bean Scripting Framework" - which started as an IBM project - lets you run scripting languages from Java.
Here is the current home page at the Apache Software Foundation
BSF supports several scripting languages currently:
Javascript (using Rhino ECMAScript, from the Mozilla project)
Python (using either Jython or JPython)
Tcl (using Jacl)
NetRexx (an extension of the IBM REXX scripting language in Java)
XSLT Stylesheets (as a component of Apache XML project's Xalan and Xerces)

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!