## javax.script.http
Interface HttpScriptContext

All Superinterfaces:
  ScriptContext

All Known Implementing Classes:
  SimpleHttpScriptContext

    public interface HttpScriptContext

extends ScriptContext

HttpScriptContext is a subinteface of ScriptContext which is used to connect a ScriptEngine and implicit objects form a servlet container to for a single request.

Author:
  Nandika Jayawardana <nandika@opensource.lk>, Sanka Samaranayake <sanka@opensource.lk>

Field Summary
`static int` `APPLICATION_SCOPE` Integer value for the level of APPLICATION_SCOPE
`static int` `REQUEST_SCOPE` Integer value for the level of REQUEST_SCOPE
`static int` `SESSION_SCOPE` Integer value for the level of SESSION_SCOPE

Fields inherited from interface javax.script.ScriptContext
`ENGINE_SCOPE, GLOBAL_SCOPE`

Method Summary
`boolean` `disableScript()` Retrieves a boolean value which indicates whether the script execution has been disabled in the Web Application.
`boolean` `displayResults()` Retrieves a boolean value which indicates whether the HttpScriptServlet executing in this context should display the results of script evaluations.
`void` `forward(java.lang.String relativePath)` Forwards the request to the resource identified by the specified relative path.
`java.lang.String[]` `getAllowedLanguages()` Retrieves an array of Strings describing the languages that may be used by scripts which is running in the associated HttpScriptContext.
`java.lang.Object` `getAttribute(java.lang.String name)` Retrieves the value for the specified key in the lowest scope in which the key is defined.
`java.lang.Object` `getAttribute(java.lang.String name, int scope)` Retrieves the value associated with the specified key in specified level of scope.
`java.lang.String[]` `getMethods()` Retrieves an array of string describing HTTP request methods which are handled by servlets executing in current context.
`javax.servlet.http.HttpServletRequest` `getRequest()` Retrieves a HttpScriptRequest for the current request.
`javax.servlet.http.HttpServletResponse` `getResponse()` Retrieves a HttpScriptResponse for the current request.
`java.io.Reader` `getScriptSource()` Retrieves a reader form which the executing script can be read.
`javax.servlet.Servlet` `getServlet()` Retrieves the associated HttpScriptServlet.
`void` `include(java.lang.String relativePath)` Includes the resource in the sepcified relative path.
`void` `initialize(javax.servlet.Servlet servlet, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)` Initialize the current HttpScriptContext for processing of single request.
`void` `release()` Clears any state stored in the current HttpScriptContext such that it can be reused to serve another request.
`void` `setAttribute(java.lang.String name, java.lang.Object value, int scope)` Sets the value for the specified key in the specified level of scope.
`boolean` `useSession()` Retrieves a boolean value which indicates whether the HttpSession associated with the current request is exposed in SESSION_SCOPE attribute and in the HttpScriptRequest.

Methods inherited from interface javax.script.ScriptContext
`getAttributesScope, getBindings, getWriter, removeAttribute, setBindings`

Field Detail

### REQUEST_SCOPE

    static final int REQUEST_SCOPE

  Integer value for the level of REQUEST_SCOPE

  See Also:
    Constant Field Values

### SESSION_SCOPE

    static final int SESSION_SCOPE

  Integer value for the level of SESSION_SCOPE

  See Also:
    Constant Field Values

### APPLICATION_SCOPE

    static final int APPLICATION_SCOPE

  Integer value for the level of APPLICATION_SCOPE

  See Also:
    Constant Field Values

Method Detail

### disableScript

    boolean disableScript()

  Retrieves a boolean value which indicates whether the script execution has been disabled in the Web Application.

  Returns:
    a booean indicating whether the script execution is allowed

### displayResults

    boolean displayResults()

  Retrieves a boolean value which indicates whether the HttpScriptServlet executing in this context should display the results of script evaluations.

  Returns:
    a boolean indicating whether the results of script eveluations should be displayed

### forward

    void forward(java.lang.String relativePath)
                 throws javax.servlet.ServletException,
                        java.io.IOException

  Forwards the request to the resource identified by the specified relative path.

  Parameters:
    `relativePath` - the URI to process the request
  Throws:
    `java.io.IOException` - if an input or output error occurs while processing the HTTP request
    `javax.servlet.ServletException` - if the HTTP cannot be handled

### getAllowedLanguages

    java.lang.String[] getAllowedLanguages()

  Retrieves an array of Strings describing the languages that may be used by scripts which is running in the associated HttpScriptContext. Returns null if no restrictions apply.

  Returns:
    a String array of permitted languages

### getAttribute

    java.lang.Object getAttribute(java.lang.String name)

  Retrieves the value for the specified key in the lowest scope in which the key is defined. Returns null if the specified key is not defiend in any scope.

  Specified by:
    `getAttribute` in interface `ScriptContext`
  Parameters:
    `name` - the name of the value to be retrieved
  Returns:
    the value associated with the specified key

### getAttribute

    java.lang.Object getAttribute(java.lang.String name,
                                  int scope)
                                  throws java.lang.IllegalArgumentException

  Retrieves the value associated with the specified key in specified level of scope.

  Specified by:
    `getAttribute` in interface `ScriptContext`
  Parameters:
    `scope` - the integer value of level of scope
    `name` - the name of the attribute
  Returns:
    the value associated with specified key in the specified level of scope
  Throws:
    `java.lang.IllegalArgumentException` - if name is null or the scope is invalid

### getMethods

    java.lang.String[] getMethods()

  Retrieves an array of string describing HTTP request methods which are handled by servlets executing in current context.

  Returns:
    a String array of HTTP request methods handled by servelts in the current context

### getRequest

    javax.servlet.http.HttpServletRequest getRequest()

  Retrieves a HttpScriptRequest for the current request. If the session state is disabled, an adapter whose getSession() method returns null should be used.

  Returns:
    the current request

### getResponse

    javax.servlet.http.HttpServletResponse getResponse()

  Retrieves a HttpScriptResponse for the current request.

  Returns:
    the current response

### getScriptSource

    java.io.Reader getScriptSource()

  Retrieves a reader form which the executing script can be read.

  Returns:
    a reader from which the script can be read.

### getServlet

    javax.servlet.Servlet getServlet()

  Retrieves the associated HttpScriptServlet.

  Returns:
    a reader form which the script source can be read

### include

    void include(java.lang.String relativePath)
                 throws java.io.IOException,
                        javax.servlet.ServletException

  Includes the resource in the sepcified relative path.

  Parameters:
    `relativePath` - the URI of the request to be processed
  Throws:
    `java.io.IOException` - if an input or output error occurs while processing the HTTP request
    `javax.servlet.ServletException` - if the servlet cannot handled the HTTP request

### initialize

    void initialize(javax.servlet.Servlet servlet,
                    javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse res)
                    throws javax.servlet.ServletException

  Initialize the current HttpScriptContext for processing of single request. Implementation must initialize request, session and application scopes. Further it should store servlet, request and response references for use.

  Parameters:
    `servlet` - the HttpServlet which execute the request
    `req` - the current request
    `res` - the current response
  Throws:
    `javax.servlet.ServletException` - if the servlet cannot handle the HTTP request

### release

    void release()

  Clears any state stored in the current HttpScriptContext such that it can be reused to serve another request.

### setAttribute

    void setAttribute(java.lang.String name,
                      java.lang.Object value,
                      int scope)

  Sets the value for the specified key in the specified level of scope.

  Specified by:
    `setAttribute` in interface `ScriptContext`
  Parameters:
    `name` - the key associated with the specified value
    `value` - the value associated with the specified key
    `scope` - the level of scope
  Throws:
    `java.lang.IllegalArgumentException` - if the level of scope is invalid
    `java.lang.IllegalStateException` - if the session is either invalid or diabled

### useSession

    boolean useSession()

  Retrieves a boolean value which indicates whether the HttpSession associated with the current request is exposed in SESSION_SCOPE attribute and in the HttpScriptRequest.

  Returns:
    a boolean value which indicates whether the session is vaild