B4J Programming Press on the image to return to the main documentation page.

jServer

List of types:

ConnectionPool
Cookie
Future
HttpSession
JQueryElement
Part
Server
ServletRequest
ServletResponse
SslConfiguration
WebSocket

ConnectionPool

Maintains a pool of database connections.

Events:

ConnectionReady (Success As Boolean, SQL As SQL)

Members:


  ClosePool

  GetConnection As SQL

  GetConnectionAsync (EventName As String)

  Initialize (DriverClass As String, JdbcUrl As String, User As String, Password As String)

  IsInitialized As Boolean

Members description:

ClosePool
GetConnection As SQL
Retrieves a connection from the pool. Make sure to close the connection when you are done with it.
GetConnectionAsync (EventName As String)
Asynchronously gets a SQL connection. This method is useful in UI applications as it prevents the main thread from freezing until the connection is available.
The ConnectionReady event will be raised when the connection is ready.
Initialize (DriverClass As String, JdbcUrl As String, User As String, Password As String)
Initializes the pool.
DriverClass - The JDBC driver class.
JdbcUrl - JDBC connection url.
User / Password - Connection credentials.
IsInitialized As Boolean

Cookie

Represents a HTTP cookie. You can add cookies to the response with ServletResponse.AddCookie.
These cookies will then be sent in the following browser requests.
You can fetch the cookies with ServletRequest.GetCookies.

Events:

None

Members:


  Initialize (Name As String, Value As String)

  IsInitialized As Boolean

  MaxAge As Int

  Name As String [read only]

  Value As String

Members description:

Initialize (Name As String, Value As String)
Creates a new cookie with the given name and value.
IsInitialized As Boolean
MaxAge As Int
Gets or sets the cookie maximum age in seconds.
A negative value means that the cookie will be deleted when the Web browser exists.
A zero value causes the cookie to be deleted.
Name As String [read only]
Gets the cookie name.
Value As String
Gets or sets the cookie value.

Future

Holds a reference to a value. The value may not be currently available.
In that case the thread will wait for it to be available when you call Value.

Events:

None

Members:


  Value As Object [read only]

Members description:

Value As Object [read only]
If the value is already available then it is immediately returned. Otherwise the thread will wait for it to be available.

HttpSession

HttpSessions allows you to identify a user across multiple requests and to store data specific to this user.
The session id is stored as a cookie in the user browser, or as a URL parameter if cookies are disabled.
The data is stored in the server memory.
Getting and creating sessions is done with ServletRequest.GetSession.

Events:

None

Members:


  CreationTime As Long [read only]

  GetAttribute (Name As String) As Object

  GetAttribute2 (Name As String, DefaultValue As Object) As Object

  GetAttributesNames As List

  HasAttribute (Name As String) As Boolean

  Id As String [read only]

  Invalidate

  IsInitialized As Boolean

  IsNew As Boolean [read only]

  LastAccessedTime As Long [read only]

  MaxInactiveInterval As Int

  RemoveAttribute (Name As String)

  SetAttribute (Name As String, Value As Object)

Members description:

CreationTime As Long [read only]
Returns the session creation time.
GetAttribute (Name As String) As Object
Returns the value tied to the attribute with the specified name.
GetAttribute2 (Name As String, DefaultValue As Object) As Object
Returns the value tied to the attribute with the specified name.
Returns the DefaultValue if no value exists.
GetAttributesNames As List
Returns a List with all the session names.
HasAttribute (Name As String) As Boolean
Tests whether there is a value tied to the given name.
Id As String [read only]
Returns the session unique id.
Invalidate
Invalidates the session. This causes the session to be deleted.
IsInitialized As Boolean
IsNew As Boolean [read only]
Returns true if the session was created in this request.
LastAccessedTime As Long [read only]
Returns the last time the user sent a request associated with this session.
MaxInactiveInterval As Int
Gets or sets the maximum inactive interval, in seconds. The session will be invalidated if there was not any activity for a period larger than this value.
The default value is -1 which means that there is no maximum interval.
RemoveAttribute (Name As String)
Removes the attribute with the given name.
SetAttribute (Name As String, Value As Object)
Adds an attribute to the session. If there is an existing value with the same name then it will be replaced.

JQueryElement


Events:

Change (Params As Map)
Click (Params As Map)
DblClick (Params As Map)
Focus (Params As Map)
FocusIn (Params As Map)
FocusOut (Params As Map)
KeyUp (Params As Map)
MouseDown (Params As Map)
MouseEnter (Params As Map)
MouseLeave (Params As Map)
MouseMove (Params As Map)
MouseUp (Params As Map)

Members:


  GetCSS (Property As String) As Future

  GetHeight As Future

  GetHtml As Future

  GetProp (Property As String) As Future

  GetText As Future

  GetVal As Future

  GetWidth As Future

  Id As String [read only]

  RunMethod (Method As String, Params As List)

  RunMethodWithResult (Method As String, params As List) As Future

  SetCSS (Property As String, Value As String)

  SetHeight (Value As String)

  SetHtml (Value As String)

  SetProp (Property As String, Value As Object)

  SetText (Value As String)

  SetVal (Value As Object)

  SetWidth (Value As String)

Members description:

GetCSS (Property As String) As Future
Returns the result of jQuery CSS method.
GetHeight As Future
Returns the result of jQuery height method.
GetHtml As Future
Returns the result of jQuery html method.
GetProp (Property As String) As Future
Returns the result of jQuery prop method.
GetText As Future
Returns the result of jQuery text method.
GetVal As Future
Returns the result of jQuery val method.
GetWidth As Future
Returns the result of jQuery width method.
Id As String [read only]
RunMethod (Method As String, Params As List)
Runs the given jQuery method.
Params - List or array of values to pass to the method. Set to Null if not needed.
RunMethodWithResult (Method As String, params As List) As Future
Similar to RunMethod. The result of the method is returned as a Future object.
SetCSS (Property As String, Value As String)
Calls jQuery css method with the given property and value.
SetHeight (Value As String)
Calls jQuery height method with the given value.
SetHtml (Value As String)
SetProp (Property As String, Value As Object)
Calls jQuery prop method with the given value.
SetText (Value As String)
Calls jQuery text method with the given value.
SetVal (Value As Object)
Calls jQuery val method with the given value.
SetWidth (Value As String)
Calls jQuery width method with the given value.

Part


Events:

None

Members:


  GetValue (CharacterEncoding As String) As String

  IsFile As Boolean [read only]

  IsInitialized As Boolean

  SubmittedFilename As String [read only]

  TempFile As String [read only]

Members description:

GetValue (CharacterEncoding As String) As String
Returns the string value of this part. This should only be used with non-files parts.
IsFile As Boolean [read only]
Returns true if this part represents a file.
IsInitialized As Boolean
SubmittedFilename As String [read only]
Returns the submitted file name.
TempFile As String [read only]
Returns the path to the temporary file.

Server


Events:

None

Members:


  AddBackgroundWorker (Class As String)

  AddDoSFilter (Path As String, Settings As Map)

  AddFilter (Path As String, Class As String, SingleThreadHandler As Boolean)

  AddHandler (Path As String, Class As String, SingleThreadHandler As Boolean)

  AddWebSocket (Path As String, Class As String)

  CreateThreadSafeMap As Map

  CurrentThreadIndex As Int [read only]

  DebugNetworkLatency As Int [write only]

  GzipEnabled As Boolean [write only]

  Http2Enabled As Boolean

  Initialize (EventName As String)

  LogsFileFolder As String

  LogsRetainDays As Int

  LogWaitingMessages As Boolean

  Port As Int

  SetCustomErrorPages (PagesMap As Map)

  SetSslConfiguration (Config As SslConfiguration, Port As Int)

  SetStaticFilesOptions (Options As Map)

  SslPort As Int [read only]

  Start

  StaticFilesFolder As String

Members description:

AddBackgroundWorker (Class As String)
Adds a background worker. An instance of the specified class will be created and initialized from a background thread.
Class - The class name. The class should be a standard class (not server handler).

You can call StartMessageLoop in the Initialize sub to keep the class instance running for as long as needed.
Note that in debug mode the code will be executed by the main thread.
AddDoSFilter (Path As String, Settings As Map)
Adds a filter that protects against intentional or unintentional denial of service attacks.
It restricts the number of requests sent from the same connection.
Path - The filter will be mapped to the given path. You can use wildcards in the path.
Settings - An optional map with various settings. See this link:
DoS Filter Documentation

Example:srvr.AddDoSFilter("/*", Null)
AddFilter (Path As String, Class As String, SingleThreadHandler As Boolean)
Maps a filter class.
Path - The filter will be mapped to the following path. You can use wildcards in the path.
Class - The class name (string).
SingleThreadHandler - Whether this handler should always run in the main thread.
AddHandler (Path As String, Class As String, SingleThreadHandler As Boolean)
Maps a handler class.
Path - The handler will be mapped to the following path. You can use wildcards in the path.
Class - The class name (string).
SingleThreadHandler - Whether this handler should always run in the main thread.
AddWebSocket (Path As String, Class As String)
Maps a WebSocket class.
Path - The WebSocket will be mapped to this path.
Class - WebSocket class (string).
CreateThreadSafeMap As Map
Returns an initialized Map that can safely be accessed by multiple threads (based on Java ConcurrentHashMap).
Unlike the standard Map the order of items is not preserved.
Note that this Map does not support the following methods: GetKeyAt and GetValueAt.
CurrentThreadIndex As Int [read only]
Each thread is mapped to a specific index. This property returns the current thread index.
Note that the main thread index is always 0.
DebugNetworkLatency As Int [write only]
Sets the emulated network latency in debug mode, measured in milliseconds.
Default value is 100.
You should only call this method before the server is started.
The emulated latency only affects server -> client -> server round-trips.
GzipEnabled As Boolean [write only]
Calling this method will cause the server to compress the responses if the client supports GZIP responses and the resource mime type is not of a known compressed type.
In most cases it should be enabled.
Http2Enabled As Boolean
Gets or sets whether Http/2.0 is enabled. Note that it requires some configuration (see the tutorial for more information).
Initialize (EventName As String)
Initializes the server.
EventName is currently not used.
LogsFileFolder As String
Gets or sets the logs files folder.
LogsRetainDays As Int
Gets or sets the number of days the rotated logs will be kept.
LogWaitingMessages As Boolean
Sets whether "waiting for value" messages are logged.
These messages can help you to optimize the code and reduce the network latency effects.
Port As Int
Gets or sets the server port.
SetCustomErrorPages (PagesMap As Map)
This method allows you to set custom error pages.
The PagesMap maps between status codes (such as 404 and 500) and the handlers or pages that will be called for each error.
This method should be called before the server is started.
Example:
Dim err As Map
err.Initialize
err.Put(404, "/404.html") 'map to a custom page
srvr.SetCustomErrorPages(err)
SetSslConfiguration (Config As SslConfiguration, Port As Int)
Configures the SSL connector and sets the port used for https connections.
SetStaticFilesOptions (Options As Map)
A Map with configuration parameters that affect the way the server serves static files.
See this link for more information:
http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/servlet/DefaultServlet.html.
SslPort As Int [read only]
Returns the port used for SSL (https) connections.
Start
Starts the server. The handlers and the configuration settings should be set before the server is started.
StaticFilesFolder As String
Gets or sets the static files folder.

ServletRequest


Events:

None

Members:


  CharacterEncoding As String [read only]

  ContentLength As Int [read only]

  ContentType As String [read only]

  FullRequestURI As String [read only]

  GetCookies As Cookie()

  GetHeader (Name As String) As String

  GetHeaders (Name As String) As List

  GetMultipartData (Folder As String, MaxSize As Long) As Map

  GetParameter (Name As String) As String

  GetParameterValues (Name As String) As String()

  GetSession As HttpSession

  InputStream As InputStreamWrapper [read only]

  IsInitialized As Boolean

  Method As String [read only]

  ParameterMap As Map [read only]

  RemoteAddress As String [read only]

  RequestURI As String [read only]

  Secure As Boolean [read only]

Members description:

CharacterEncoding As String [read only]
Returns the request character encoding or an empty string if the encoding is not available.
ContentLength As Int [read only]
Returns the request content length.
ContentType As String [read only]
Returns the request content type header or an empty string if the content type is not available.
FullRequestURI As String [read only]
Returns the full request URL including the scheme, host and parameters.
GetCookies As Cookie()
Returns an array with the request cookies.
GetHeader (Name As String) As String
Returns the header value or an empty string if the header does not exist.
GetHeaders (Name As String) As List
Returns a list with all the headers values mapped to the specified header.
GetMultipartData (Folder As String, MaxSize As Long) As Map
Parses a multipart request and returns a Map with the parsed Parts as values and the parts names as keys.
Folder - The files will be saved in this folder.
MaxSize - The request maximum size.
GetParameter (Name As String) As String
Returns the parameter value or an empty string if the parameter does not exist.
GetParameterValues (Name As String) As String()
GetSession As HttpSession
Gets the user session. A new session will be created if this is the first request from this user.
InputStream As InputStreamWrapper [read only]
Returns an InputStream that allows you to read directly from the request body.
IsInitialized As Boolean
Method As String [read only]
Returns the HTTP method (GET or POST).
ParameterMap As Map [read only]
Returns a Map with all the parameter. The keys are the parameters names (strings) and the values are the parameters values (arrays of strings).
RemoteAddress As String [read only]
Returns the client IP address.
RequestURI As String [read only]
Returns the request URL without the host and any parameters.
Secure As Boolean [read only]
Returns true if the request was made with a secure channel (SSL).

ServletResponse


Events:

None

Members:


  AddCookie (Cookie As Cookie)

  CharacterEncoding As String

  ContentLength As Int [write only]

  ContentType As String

  ErrorReason As String [read only]

  IsInitialized As Boolean

  OutputStream As OutputStreamWrapper [read only]

  SendError (StatusCode As Int, Message As String)

  SendRedirect (Location As String)

  SetHeader (Name As String, Value As String)

  Status As Int

  Write (Text As String) As ServletResponse

Members description:

AddCookie (Cookie As Cookie)
Adds a cookie to the response.
CharacterEncoding As String
Gets or sets the response character encoding.
ContentLength As Int [write only]
Sets the response content length header.
ContentType As String
Gets or sets the response content type.
ErrorReason As String [read only]
Returns the error string that is tied to this response. This is useful with handlers that act as custom error pages.
IsInitialized As Boolean
OutputStream As OutputStreamWrapper [read only]
Returns an OutputStream that can be used to write bytes directly to the response stream.
SendError (StatusCode As Int, Message As String)
Sends an error message.
StatusCode - Usually 500.
Message - The error message.
SendRedirect (Location As String)
Sends a redirect response with the status code 302.
Location - The new address.
SetHeader (Name As String, Value As String)
Sets the request header.
Status As Int
Gets or sets the response status code.
Note that you should use SendError to send error statuses. Otherwise the custom error pages will be skipped.
Write (Text As String) As ServletResponse
Writes the text to the response stream.

SslConfiguration

Holds the key store configuration.

Events:

None

Members:


  Initialize

  IsInitialized As Boolean

  KeyManagerPassword As String [write only]

  KeyStorePassword As String [write only]

  SetKeyStorePath (Dir As String, FileName As String)

Members description:

Initialize
IsInitialized As Boolean
KeyManagerPassword As String [write only]
Sets the key password.
KeyStorePassword As String [write only]
Sets the keystore password.
SetKeyStorePath (Dir As String, FileName As String)
Sets the path to the keystore file.

WebSocket


Events:

None

Members:


  Alert (Message As String)

  Close

  Eval (Script As String, Args As List)

  EvalWithResult (Script As String, Args As List) As Future

  Flush

  GetElementById (Id As String) As JQueryElement

  GetElementBySelector (Selector As String) As JQueryElement

  Open As Boolean [read only]

  RunFunction (Function As String, Args As List)

  RunFunctionWithResult (Function As String, Args As List) As Future

  Secure As Boolean [read only]

  Session As HttpSession [read only]

  UpgradeRequest As ServletRequest [read only]

Members description:

Alert (Message As String)
Calls JavaScript Alert method (shows a dialog).
Close
Closes the WebSocket connection.
Eval (Script As String, Args As List)
Creates a new JavaScript function with the Script parameter as the body and runs it. Args is an optional list of arguments to pass to this function.
EvalWithResult (Script As String, Args As List) As Future
Similar to Eval. Returns the result of this function. Make sure to return a value from the script.
Flush
Flushes the output stream. Flush is called automatically when client events complete.
You need to explicitly call it at the end of server events.
GetElementById (Id As String) As JQueryElement
Creates a JQueryElement object mapped to the given id.
This is equivalent to GetElementBySelector("#" & id.ToLowerCase).
GetElementBySelector (Selector As String) As JQueryElement
Creates a JQueryElement object mapped to the given selector.
Open As Boolean [read only]
Returns true if the connection is open.
RunFunction (Function As String, Args As List)
Runs a JavaScript function. Pass null to Args if it is not needed.
RunFunctionWithResult (Function As String, Args As List) As Future
Similar to RunFunction. Returns the result of the function.
Secure As Boolean [read only]
Returns true if the request was made with a secure channel (SSL).
Session As HttpSession [read only]
Returns the http session object which is tied to the current user.
UpgradeRequest As ServletRequest [read only]
Gets the upgrade request object. This is the request that started the WebSocket connection.
Top