Results 1 to 5 of 5

Thread: Problem with Jsp Functions

  1. #1
    Join Date
    Oct 2008
    Beans
    68

    Problem with Jsp Functions

    Hi
    I am starting with JSP.
    I would like to know why this doesn't work?

    Code:
    <%String msg="Hola"; %>
    <%! public void getMsg()
    {
     out.print(msg);
    }%>
    This fragmement of code doesn't work?
    The errors that appear are out cannot be resolved and msg cannot be resolved.

    Any idea?
    Last edited by DiegoTc; July 24th, 2012 at 05:32 PM.

  2. #2
    Join Date
    Jul 2008
    Location
    England
    Beans
    866

    Re: Problem with Jsp Functions

    Just a guess but do you not want:
    Code:
    System.out.print(msg);
    ?

    as for msg.. that is in a different set of JSP tags to the function. I am not 100% familiar with JSP, but, guessing again, does Java think that the function and the variable are in different scopes?

    Would
    Code:
    <%String msg="Hola";
    public void getMsg()
    {
     System.out.print(msg);
    }%>
    work?

    Paul
    My current project: http://apps.facebook.com/beatthetexan - Creating an artificial poker player using neural networks and genetic algorithms.
    My blog: http://pm-gaming.blogspot.com

  3. #3
    Join Date
    Feb 2008
    Beans
    251
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Problem with Jsp Functions

    Quote Originally Posted by PaulM1985 View Post
    Code:
     System.out.print(msg);
    I think the print function should be:

    Code:
    System.out.println( msg );
    at least, that is what I have used...
    Last edited by greenpeace; July 25th, 2012 at 06:01 PM. Reason: too many quotes!

  4. #4
    Join Date
    Jul 2008
    Location
    England
    Beans
    866

    Re: Problem with Jsp Functions

    Quote Originally Posted by greenpeace View Post
    I think the print function should be:

    Code:
    System.out.println( "msg" );
    at least, that is what I have used...
    I was assuming the OP wanted to print out the msg variable, which was the string "Hola".
    My current project: http://apps.facebook.com/beatthetexan - Creating an artificial poker player using neural networks and genetic algorithms.
    My blog: http://pm-gaming.blogspot.com

  5. #5
    Join Date
    Feb 2008
    Beans
    251
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Problem with Jsp Functions

    Quote Originally Posted by PaulM1985 View Post
    I was assuming the OP wanted to print out the msg variable, which was the string "Hola".
    Sorry you're right, no idea how those quote got in there! Edited for clarity.

    My point was that the command being "println", not "print".

Bookmarks

Posting Permissions

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