• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i use javascript inside the servlet

 
ashwini hikulkarni
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Can i use javascript inside the servlet
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowledge , you cant use JS inside servlet , because the servlets are server side java code, which run by servlet container and javaScript are script which executed by client side browser !!
 
ashwini hikulkarni
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes we can use java script inside the servlets but it will be very complicated

so what i think is to create an anathor file named as abc.js and then call the abc.js inside the servlet
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ashwini hikulkarni:
yes we can use java script inside the servlets but it will be very complicated


Actully the question you asked first was wrong (or may be the way you put it was wrong )! We cant use javascript inside the servlet code , but we can rather embed a javascript code using <script> tag into the response output stream .

Originally posted by ashwini hikulkarni:


so what i think is to create an anathor file named as abc.js and then call the abc.js inside the servlet


not clear !
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a Servlet as in a JSP you can place whatever you'd place (as a String to be sent in the response) in the final HTML page that is going to be formed from the Servlet or JSP. Of course for the servlet it will be only a String. In this String you can place HTML, Javascript or whatever you want and it will work in the navigator, but at Java level it's only a String.

Another different thing would be to use Java DOM to process an XML, or a HTML structure. Was it what you meant?

Hope I helped you.
 
K. Tsang
Bartender
Posts: 3406
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my understanding, it is possible to put js inside servlet given they embed with <html> tags.

Another thing is there is the package javax.script in JDK6, which should allow you to work with js as if it is java code. (embedding the js inside some javax.script class's method)

Yet I'm sure the first approach is much much direct and easier to accomplish.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K. Tsang:
Yet I'm sure the first approach is much much direct and easier to accomplish.
They aren't even remotely the same thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic