Discussions

Web tier: servlets, JSP, Web frameworks: JSP and declarative section (

  1. JSP and declarative section ( (1 messages)

    (See code below)
    Why won't this url initialization work in the declarative section of a jsp?
    Why can't we access the request object w/in this section?
    If the url initialization is placed out this section, f(x)s declared w/in this section cannot access them.
    Thanks for your help.

    <%!
      String url = request.getServerName() + request.getServerPort();

      // Declaring a Java class
      public Context getInitialContext() throws Exception {
       ...
      }
    %>
  2. You wont be able to use the request object while declaring member variables.

    request, response objects are not member variables and will not be available to method declarations unless passed as parameters..

    Probably you can change it as follows...


    <%
      String url = request.getServerName() + request.getServerPort();
       Context ctx = getInitialContext(url);
      
    %>

    <%!

      // Declaring a Member method
      public Context getInitialContext(String url) throws Exception {
       ...
      }
    %>