By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,362 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,362 IT Pros & Developers. It's quick & easy.

including JSP using javascript

P: n/a
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"><jsp:param name="id" value="${myid}" /></jsp:include>';

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

Feb 22 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Feb 22, 12:52 pm, "Pablo" <gom...@gmail.comwrote:
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"><jsp:param name="id" value="${myid}" /></jsp:include>';

Does anyone have a clue of what is going wrong? Maybe an alternative
solution?
Regards,
Pablo
Remember that javascript is executed on the client side, within the
browser (or other client device). JSP includes must be rendered on the
server (JSP is a server side technology). This idea will never work
for you... By the time the client is executing javascript, the server
has already done it's job and is waiting for the next request.

I've never experimented with it but you could possibly make an
XmlHTTPRequest for the jsp and be sent the processed result, and then
include it. But this is probably not at all they way you want to go
about this. Why can't the JSP do al the processing on the server side?
Is the "not a database" resource not available to the JSP?

Feb 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.