Forums Register Login

can i use javascript inside the servlet

+Pie Number of slices to send: Send
Hi all
Can i use javascript inside the servlet
+Pie Number of slices to send: Send
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 !!
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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 !
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
I will open the floodgates of his own worst nightmare! All in a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4987 times.
Similar Threads
calling a servlet from javascript function??
Please Help! How to create Modal Dialog Box in Servlet.
using javascripts in servlet?
How to assign a javascript variable to java varisble?
Encode java, decode javascript
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:29:57.