Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > including JSP using javascript

Reply
Thread Tools

including JSP using javascript

 
 
Pablo
Guest
Posts: n/a
 
      02-22-2007
Dear all,

I have a website where I need to fill its contents after retrieving
some data from another system (not a DB, but you can think like it).
I know the nature of the data, but the order that it is retrieved is
random, and there is no way to order it. Therefore, it is giving me
some pain to produce the html code.
I was thinking of having the following javascript to place my html
code. Here, "rightImg" is the ID of a DIV tag where I want to position
my code. The code should be the content of the htmlBody variable.

function addTopRightImage() {
var htmlBody = '.';
if (document.all) {
document.all('rightImg').innerHTML = htmlBody;
}
else if (document.getElementById) {
document.getElementById('rightImg').innerHTML = htmlBody;
}
}

However, if I set the variable as it is shown bellow, the page is not
loaded as I want:

var htmlBody = '<jsp:include page="/WEB-INF/Standard.jsp"
flush="true"><jsparam name="id" value="${myid}" /></jsp:include>';

Does anyone have a clue of what is going wrong? Maybe an alternative
solution?
Regards,
Pablo

 
Reply With Quote
 
 
 
 
Meke
Guest
Posts: n/a
 
      02-22-2007
Pablo wrote:

> Dear all,
>
> I have a website where I need to fill its contents after retrieving
> some data from another system (not a DB, but you can think like it).
> I know the nature of the data, but the order that it is retrieved is
> random, and there is no way to order it. Therefore, it is giving me
> some pain to produce the html code.
> I was thinking of having the following javascript to place my html
> code. Here, "rightImg" is the ID of a DIV tag where I want to position
> my code. The code should be the content of the htmlBody variable.
>
> function addTopRightImage() {
> var htmlBody = '.';
> if (document.all) {
> document.all('rightImg').innerHTML = htmlBody;
> }
> else if (document.getElementById) {
> document.getElementById('rightImg').innerHTML = htmlBody;
> }
> }
>
> However, if I set the variable as it is shown bellow, the page is not
> loaded as I want:
>
> var htmlBody = '<jsp:include page="/WEB-INF/Standard.jsp"
> flush="true"><jsparam name="id" value="${myid}" /></jsp:include>';
>
> Does anyone have a clue of what is going wrong? Maybe an alternative
> solution?
> Regards,
> Pablo

I think I'm correct in saying that a jsp page is compiled by the java app
server the first time it's requested by a client - much the same as a
classic servlet.
The way you are trying to do it, the jsp tag in the javascript is not seen
at compile time and get's included in the output to the client verbatum.

The key point is, I think, that the jsp is NOT translated at run time when
it is requested which it would need to be for your code to work.

Sorry for babbling, but hopefully you get the point


Mark
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-22-2007
Meke wrote:
> The key point is, I think, that the jsp is NOT translated at run time when
> it is requested which it would need to be for your code to work.

That is correct. The Javascript executes client-side after the JSP has been
generated. There is no possibility to generate HTML from JSP constructs on the
client side.

What the OP wants to do should be done server-side by the JSP. The raison
d'ĂȘtre for JSP is dynamic generation of HTML.

- Lew



 
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
Disadvantage of including JavaScript files within a JavaScript file? vunet Javascript 2 07-08-2008 03:18 PM
including JSP using javascript Pablo Javascript 1 02-22-2007 06:51 PM
Including javascript in a JSP tld misdst23 Javascript 1 09-01-2006 07:18 PM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Including an external file outside the application using JSP INCLUDE sravan Java 0 10-01-2004 04:44 PM



Advertisments