Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JSP in JavaScript

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to dynamically include some JSP in my Javascript,
but I can't get the syntax to work.
For example, Here is a simple Javascript:
document.write(" <% out.println("hello") %> ")
Can anyone help me out with this?
My real goal is to be able to include a JSP file in the Javscript:
document.write("<@ include file="myHTML.jsp" %> ")
Thanks,
Drew
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this is one solution....
document.write('<% out.print("erik"); %>');
Erik
 
Author
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your question looks a bit off? JSP executes on the server-side. You are talking about client-side JavaScript. In this sense writing out some JSP syntax to the client's browser will do nothing.
http://www.jspinsider.com/faq/2.view
However, you can have a JSP generate your JavaScript. Is this what you are trying to do?
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys,
I finally got it working by using JSP to generate the Javascript instead of trying to insert the JSP in the Javascript.
Regards,
Drew
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I've done this. Basic rule: try not to.
I has a JSP writing out Javascript which drove some DHTML.
Glad I'm not the one who had to maintain that sucker
Dave
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic