Results 1 to 7 of 7
  1. #1
    urbanleg is offline Member
    Join Date
    Jul 2011
    Posts
    25
    Rep Power
    0

    Default JSP and javascript - assignment problem

    Hi,
    I have a problem with my code:


    <code>
    <%
    String ip=request.getRemoteAddr().toString();
    System.out.println(ip); // prints the currect IP ADRESS as a string
    %>
    var ip = <%= ip %>;
    alert (ip); //DOESNT WORK!
    </code>


    the alert(ip) doesnt work at all..
    any ideas why?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: JSP and javascript - assignment problem

    Look at the source the page creates and make sure it produces what you expect, and if so make sure what you expect is valid javascript syntax

  3. #3
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: JSP and javascript - assignment problem

    as per my knowledge ,here alert is from javascript while you are working in java and jsp .Make sure that you are using right component .correct me if i am wrong as i dont know so much in jsp but knows javascript
    I can and I will

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: JSP and javascript - assignment problem

    Is the javascript inside a SCRIPT tag?
    What do you see on the page in the browser?

  5. #5
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: JSP and javascript - assignment problem

    remove var ip = and run it again it works

  6. #6
    urbanleg is offline Member
    Join Date
    Jul 2011
    Posts
    25
    Rep Power
    0

    Default Re: JSP and javascript - assignment problem

    Quote Originally Posted by vinci123 View Post
    remove var ip = and run it again it works
    Still not working,
    :(

  7. #7
    vinci123 is offline Member
    Join Date
    Aug 2011
    Location
    INDIA
    Posts
    64
    Rep Power
    0

    Default Re: JSP and javascript - assignment problem

    dear a mistake done by you .try out.println( ip); only instead of System.out.println...
    I can and I will

Similar Threads

  1. Javascript Menu Problem
    By michael_socialm in forum New To Java
    Replies: 4
    Last Post: 05-29-2011, 05:51 PM
  2. AJAX + Javascript problem
    By dapikk in forum New To Java
    Replies: 3
    Last Post: 02-22-2011, 03:12 PM
  3. sorry to ask a javascript problem but please help
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 12-23-2009, 07:33 AM
  4. Javascript problem
    By luca.santaniello in forum Advanced Java
    Replies: 2
    Last Post: 11-18-2009, 10:27 PM
  5. New Line problem in javascript
    By shuvra_pan in forum Advanced Java
    Replies: 3
    Last Post: 03-18-2009, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •