Discussions

Web tier: servlets, JSP, Web frameworks: Declaring Global Variable in JSP

  1. Declaring Global Variable in JSP (5 messages)

    Hi,
    Can you suggest a wayout of how I can declare a Global variable in JSP which can be accessed by various methods, like we do in init() method of Servlets ?

    thanx,
    dipes.

    dipes.biswas@wipro.com

    Threaded Messages (5)

  2. Declaring Global Variable in JSP[ Go to top ]

    i dont know which specification of jsp u r using but in jsp 1.1 spec there is a method called jspinit() which i think may be useful for u.
  3. Declaring Global Variable in JSP[ Go to top ]

    You can place objects in the application object. All JSPs have access to this scope, so it would indeed be global.
  4. Declaring Global Variable in JSP[ Go to top ]

    I understand what you are trying to do. But Java doesn't have the concept of global variable. Instead you can declare class members or instance members, either they are member methods or variables.
    To do this in JSP, you just need to use the declarative tag
    <% [varviable or function declaration] %>
    for example:
    <% private int id; %> declares a private integer named id;
    <% public static int id; %> declares a public integer id with class scope.
    You can also put methods inside the tag.
  5. Declaring Global Variable in JSP[ Go to top ]

    OOPS, I meant <%! ... %> rather than <% ... %>. Sorry that my finger moved too fast.

    <%! [varviable or method declaration] %>
    for example:
    <%! private int id; %><%! public static int id; %>
  6. Declaring Global Variable in JSP[ Go to top ]

    u can write a bean and store ur global variable there...