#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    0
    Rep Power
    0

    howto? using include file for global variables in JSP?


    Seems to not work in JSP but maybe I'm missing something obvious?

    In many other languages (php, perl, asp, C, whatever), I often make an "include" file which contains things like variables /constants for things like fonts, colors, etc. And even some global user-defined functions for special formatting, etc.

    How is this done in JSP? From what I can tell, this doesn't work.

    say.. inc.jsp contains:
    String g_font_face="Verdana";
    and then any file (say "foo.jsp") should be able to:
    out.print (g_font_face);
    as long as inc.jsp is "included" in "foo.jsp".

    But the following "inclusions" don't allow me to use g_font_face as a valid variable. (foo.jsp complains that g_font_face is undeclared).
    RequestDispatcher rd = request.getRequestDispatcher("inc.jsp");
    rd.include(request, response);
    =doesn't let me use any variables defined in inc.jsp

    pageContext.include("inc.jsp");
    doesn't either....

    Don't tell me JSP doesn't allow for global user-defined variables. That would really suck. But I could imagine some Object-Oriented purists saying this was a "good thing".
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Belarus
    Posts
    30
    Rep Power
    13
    hi. idoit
    it can be done with this way

    your .jsp files should begin with

    <%@include file="inc.jsp"%>

    and also for definition you can use <!% ... %> tags
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    0
    Rep Power
    0
    Alexandr,
    That was it! works great now.
    Thanks,
    John
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Belarus
    Posts
    30
    Rep Power
    13
    don't forget reading the sprcifications
    sometimes it contains something interesting

IMN logo majestic logo threadwatch logo seochat tools logo