including JSP using javascript

Discussion in 'Java' started by Pablo, Feb 22, 2007.

  1. Pablo

    Pablo Guest

    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
     
    Pablo, Feb 22, 2007
    #1
    1. Advertising

  2. Pablo

    Meke Guest

    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"><jsp:param 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
     
    Meke, Feb 22, 2007
    #2
    1. Advertising

  3. Pablo

    Lew Guest

    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
     
    Lew, Feb 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sravan
    Replies:
    0
    Views:
    2,858
    sravan
    Oct 1, 2004
  2. Replies:
    0
    Views:
    4,435
  3. misdst23

    Including javascript in a JSP tld

    misdst23, Sep 1, 2006, in forum: Javascript
    Replies:
    1
    Views:
    116
    Tom Cole
    Sep 1, 2006
  4. Pablo

    including JSP using javascript

    Pablo, Feb 22, 2007, in forum: Javascript
    Replies:
    1
    Views:
    171
    Tom Cole
    Feb 22, 2007
  5. vunet
    Replies:
    2
    Views:
    162
    Laser Lips
    Jul 8, 2008
Loading...

Share This Page