mn8 Language Reference | Index    

ServletResponse

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

Defines an object to assist a servlet in sending a response to the client.

Usage

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept

Method List

addCookie (Cookie $cookie)
addHeader (String $name, String $value)
LogicalcontainsHeader (String $name)
StringencodeRedirectURL (String $url)
StringencodeURL (String $url)
flushBuffer
IntegergetBufferSize
StringgetCharacterEncoding
LogicalisCommitted
reset
sendError (Integer $statusCode)
sendError (Integer $statusCode, String $message)
sendRedirect (String $location)
setBufferSize (Integer $bufferSize)
setContentLength (Integer $length)
setContentType (String $contentType)
setHeader (String $name, String $value)
setStatus (Integer $statusCode)
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Method Info

addCookie (Cookie $cookie)
Parameters:
$cookie :the Cookie to return to the client.
Returns:

Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.

            $cook typeof Cookie                                                     
            $cook.setName($request.getParameters.getValue("JSESSIONID"))              
            $cook.setValue($request.getParameters.getValue("zsz9mhtsz1"))
              
            $response.addCookie($cook) 

            -- the result is -- 
            Cookie: JSESSIONID=zsz9mhtsz1
        

top
addHeader (String $name, String $value)
Parameters:
$name :the name of the header.
$value :the additional header value.
Returns:

Adds a response header with the given name and value. This method allows response headers to have multiple values.

           
            $response.addHeader("MyName", "MyValue") 

            print "Contains: ", $response.containsHeader("MyValue")
            -- the result is -- 
            Contains: true
        

top
containsHeader (String $name)
Parameters:
$name :the header name.
Returns: Logical

Returns a logical indicating whether the named response header has already been set.

            $response.addHeader("MyName", "MyValue")

            print "Contain 'MyName' in header: " + $response.containsHeader("MyName")

            -- the result is --
            Contain 'MyName' in header: true
        

top
encodeRedirectURL (String $url)
Parameters:
$url :the url to be encoded.
Returns: String

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method.

All URLs sent to the ServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.


           print $response.encodeRedirectURL($request.getRequestURI)

           -- the result is --
           URL: /mn8/ServletTest.mn8
        

top
encodeURL (String $url)
Parameters:
$url :the url to be encoded.
Returns: String

Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.


           print $response.encodeURL($request.getRequestURI)

           -- the result is --
           URL: /mn8/ServletTest.mn8
        

top
flushBuffer
Returns:

Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.


           $response.flushBuffer

           -- the result is --
           Content of buffer is writed to the client.
        

top
getBufferSize
Returns: Integer

Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.


            print "<p><b>Buffer Size: </b>" ,$response.getBufferSize

            -- the result is --
            Buffer Size: 8192
        

top
getCharacterEncoding
Returns: String

Returns the name of the charset used for the MIME body sent in this response.

If no charset has been assigned, it is implicitly set to ISO- 8859-1 (Latin-1).

See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt ) for more information about character encoding and MIME.


            print "<p><b>Encoding: </b>" ,$response.getCharacterEncoding

            -- the result is --
            Encoding: ISO-8859-1
        

top
isCommitted
Returns: Logical

Returns a logical indicating if the response has been committed. A commited response has already had its status code and headers written.


            print "<p><b>Commited: </b>" ,$response.isCommited

            -- the result is --
            Commited: false
        

top
reset
Returns:

Clears any data that exists in the buffer as well as the status code and headers. If the response has been committed, this method throws an IllegalStateException.


           $response.reset

           -- the result is --
           Clears the data from buffer.
        

top
sendError (Integer $statusCode)
Parameters:
$statusCode :the error status code.
Returns:

Sends an error response to the client using the specified status. The server generally creates the response to look like a normal server error page.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.


           $response.sendError(501)

           -- the result is --
           Send an error response to the client using the specified status.
        

top
sendError (Integer $statusCode, String $message)
Parameters:
$statusCode :the error status code.
$message :the descriptive message.
Returns:

Sends an error response to the client using the specified status code and descriptive message. The server generally creates the response to look like a normal server error page.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.


           $response.sendError(501, "This is a error.")

           -- the result is --
           Send an error rwsponse to the client using the specified status
           and descriptive message.
        

top
sendRedirect (String $location)
Parameters:
$location :the redirect location URL.
Returns:

Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container will convert the relative URL to an absolute URL before sending the response to the client.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

        
            $response.sendRedirect( $response.encodeRedirectURL($request.getRequestURI) ) 
        
            -- the response is -- 
            Send a redirect response to the client.
        

top
setBufferSize (Integer $bufferSize)
Parameters:
$bufferSize :the preferred buffer size.
Returns:

Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written, this method throws an IllegalStateException.

          
            $response.setBufferSize(4096) 

            print "<p><b>Buffer Size: </b>" ,$response.getBufferSize
            -- the result is --
            Buffer Size: 4096
        

top
setContentLength (Integer $length)
Parameters:
$length :an integer specifying the length of the content being returned to the client; sets the Content-Length header
Returns:

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

          
            $response.setContentLength(4096) 

            -- the result is --
            Sets the content length of the content body to 4096.
        

top
setContentType (String $contentType)
Parameters:
$contentType :a String specifying the MIME type of the content.
Returns:

Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example, text/html; charset=ISO-8859-4.

          
            $response.setContentType("text/html") 

            print "Content-Type: ",$request.getContentType
            -- the result is --
            Content-Type: text/html
        

top
setHeader (String $name, String $value)
Parameters:
$name :the name of the header.
$value :the header value.
Returns:

Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

           
            $response.setHeader("MyName", "MyValue") 

            print "Contains: ", $response.containsHeader("MyValue")
            -- the result is -- 
            Contains: true
        

top
setStatus (Integer $statusCode)
Parameters:
$statusCode :the status code.
Returns:

Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes OK(200) or MOVED TEMPORARILY(302). If there is an error, the sendError method should be used instead.

top