Jaxcent also includes a small standalone web server, that can be started from the command line.
To use this server, the files
need to be in the classpath.
To start the server from the command line, the syntax is:
java jaxcentServer.ServerMain <port-number> <HTML-root> <XML-Config-file> <Optional-Reloadable-classpath>For instance,
java jaxcentServer.ServerMain 80 C:\MyHtmlFiles C:\JaxcentConfig.xmlor
java jaxcentServer.ServerMain 80 C:\MyHtmlFiles C:\JaxcentConfig.xml C:\MyJaxcentClassesIf the <Optional-Reloadable-classpath> is provided, Jaxcent will look in there for classes to load (in addition to the standard classpath), and will reload these classes whenever they change. This can help during development. (But should not be used if running within an IDE.)
In addition, the Jaxcent server can also be started programmatically. To do this, instantiate the class
jaxcentServer.ServerMain. This class extends
instantiating it, start the thread. E.g.
ServerMain jaxcentServer = new ServerMain( 80, htmlDir, xmlConfigFile, reloadableClasspath ); jaxcentServer.start();The last parameter
null. In debugging, typically you may want to provide
nullhere, and specify the full classpath in the IDE.
It can also be configured to work directly with Microsoft IIS web-server, or the Apache web-server.
If using a Java servlet container, Apache or IIS, the file jaxcent21.js must be made available at the URL location.
/jaxcent21.jsThis URL location can be changed, but the HTML files must have the correct URL.
Also, the Jaxcent servlet (or connector) needs to be available at the URL location
/servlet/JaxcentServlet21This URL location can also be changed, and would require editing the jaxcent21.js file to specify the correct URL.
Depending upon your environment, please visit the appropriate link below for configuring the Jaxcent servlet/connector.
<JaxcentConfiguration> <Page> <PagePath>/clockSample.html</PagePath> <PageClass>sample.ClockSample</PageClass> </Page> <Page> <PagePath>/clockImageSample.html</PagePath> <PageClass>sample.ClockImageSample</PageClass> </Page> <Page> <PagePath>/WidgetsSample.html</PagePath> <PageClass>sample.WidgetsSample</PageClass> </Page> <Page> <PagePath>/TableSample.html</PagePath> <PageClass>sample.TableSample</PageClass> </Page> <Page> <PagePath>/ChatSample.html</PagePath> <PageClass>sample.ChatSample</PageClass> </Page> </JaxcentConfiguration>
If necessary, edit jaxcent21.js to provide the correct URL for the Jaxcent servlet/connector.
Note: This step is not applicable if you are using the Jaxcent Development Server, because jaxcent21.js is embedded in the server itself.
The Jaxcent classes (jaxlets) you write must extend jaxcent.JaxcentPage, and can override various methods in there. Typically, you can declare and initialize one or more fields corresponding to one or more HTML tags on the page. You can access methods and properties of these HTML tags directly from your Jaxcent class.
Jaxcent has classes corresponding to various HTML tags. The class jaxcent.HtmlElement is a catch-all class that you can use if you are not particular about using the exact matching class.
When you create an object of a class corresponding to an HTML tag, Jaxcent needs a way to locate the actual tag on the HTML page. This is done by providing a "search" method. The default (and recommended) search method is to search by the "ID" field. This requires adding an ID attribute to the HTML field, and then specifying the same ID string to the corresponding Jaxcent object's constructor.
There are other methods of locating the HTML tags on the page, as well, such as searching by the tag or by NAME or by TYPE (applies to INPUT tags).
New elements can be created by using the createNew argument instead of a search-type.
If you are interested in receiving events from any of the objects you have created, simply override the event method.
The processing typically starts by overriding the onLoad method of jaxcent.JaxcentPage class, or from event handlers. Before onLoad is called (in the constructor), data cannot be retrieved from the HTML page, because the page has not loaded yet. However, data can be sent out, and values of fields can be set in the constructor. These will get queued up, and will be processed when the page does get loaded.
The provided samples can be compiled, tested and reviewed for a good start.
The rest of the web application's behavior can continue as it used to.
When designing new applications using Jaxcent, make sure to read about the configuration item "AutoSessionData". If it is configured as true, Jaxcent will save the user's data entry in the session, and when new pages are loaded, will initialize them from the session. When you are ready to process the user's data, you can also retrieve it from the session. For data verification, jaxcent.JaxcentPage provides a convenient getAllFormData method. Events can also be overridden to receive data along with the event. Alternatively, various items can be checked one at a time. In general, checking items one at a time will require many client-server round trips, so whenever reasonable, all the data should be retrieved together.
To call Java on
is sent to the server, call
is provided by the base
JaxcentGetReferencedObject( ref )to retrieve the original object from the reference.
JaxcentRemoveObjectReference( ref )to clear the reference.
Retrieving all form data with the event and responding to it with output requires only a single client-server round-trip, and typically would require only one internet packet coming in. Getting an individual item would also require one internet packet, but doing it after the event means the event requires one packet, the request to get the item requires one packet (in the other direction), and the value of the item requires one more packet!
Erroron any output to the page after the page has unloaded. This should normally have the effect of terminating the thread. However, programmers should nor rely on this mechanism and should actively terminate the thread on unload.
ReloadableClassPathis a convenient mechanism during development for having Java code changes take effect immediately. But it does require additional processing to check class files for changes. In production environments, the Jaxcent classes should be in system or app-server CLASSPATH, and not in the Jaxcent reloadable classpath, for best performance.
<FORM ID="myForm" onSubmit="return false;">or
<BUTTON ID="myButton" onClick="return false;">A Button</BUTTON>