• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

can i use javascript inside the servlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
Can i use javascript inside the servlet
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can't .... do .... plaid .... So I did this tiny ad instead:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic