Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Is it possible to put JSP code in a javascript method?

Reply
Thread Tools

Is it possible to put JSP code in a javascript method?

 
 
Ken Adams
Guest
Posts: n/a
 
      03-19-2005
Can and how does one put JSP code inside javascript code. Thanks

K


 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      03-19-2005
Ken Adams wrote:

> Can and how does one put JSP code inside javascript code.


Yes. The same way as one puts JSP code inside HTML code (although you also
have to write JSP to output a content type header of text/css, since it
would (I believe) otherwise default to text/html).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
 
Lachlan Hunt
Guest
Posts: n/a
 
      03-19-2005
Ken Adams wrote:
> Can and how does one put JSP code inside javascript code. Thanks


JSP can be written within a section of JavaScript, so long as it is
processed by the server before it is output, and the browser only
recieves the resultant JavaScript. If you were wanting a browser to
understand the JSP, then no, you can't.

eg. If this is your script.

<script type="text/javascript">
<%
/*
* Code to read from DB or other source, or whatever you need.
* Say, for example, the string "hello world" is returned, and
* set to the message variable
*/
message = "hello world";
%>
var msg = "<%=message%>";
alert(msg);
</script>

From the above JSP, the browser would recieve and execute the following
script:

<script type="text/javascript">
var msg = "hello world";
alert(msg);
</script>

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      03-19-2005
David Dorward wrote:

> Ken Adams wrote:
>
>> Can and how does one put JSP code inside javascript code.

>
> Yes. The same way as one puts JSP code inside HTML code (although you
> also have to write JSP to output a content type header of text/css,


Odd choice of Content-Type header.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      03-20-2005
Toby Inkster wrote:

>> also have to write JSP to output a content type header of text/css,

>
> Odd choice of Content-Type header.


Argle. text/javascript of course. I'm too used to answering the "variables
in CSS" question.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
[JSP] Is it possible to put a List into a session and use on a different page? Steven Java 2 03-30-2005 09:58 AM
Is it possible to put XSL instructions inside JavaScript? Matt XML 1 11-08-2004 09:41 PM
How to get the html output of a local JSP page from my Java code, or use a JSP as an HTML templates. DigitalUncle Java 0 11-02-2004 05:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57