Description of the Example Servlet
The example servlet, rwdemo, makes a connection to
a Reality database and calls a DataBasic subroutine that returns its own input
parameters to the browser. The example servlet:
- Extends
HttpServlet. - Calls the
HttpServletinit()method, then callsinit()from the RealWeb class to start a thread to timeout connections. - Overrides
doPost()to handle any post requests.doPost()is to work in exactly the same way as doGet(), so it simply callsdoGet(). - Overrides
doGet(), which is the usual entry point to the servlet.Whenever the web server receives a GET request for this servlet, the server invokes
doGet(), passing it anHttpServletRequestparameter and anHttpServletResponseparameter.Overrides
getServletInfo()to return the string "Sample RealWeb Servlet". - Includes a section of commented code showing the RW.SAMPLE subroutine to be
called by
rwdemo.The comments describe how the subroutine, which simply returns its input parameters, must be created, compiled, catalogued, then enabled. Remote Basic subroutines can be enabled for remote access by user-ids with a specified security profile (see Securing the Database Using SSM). The URL used to call the subroutine via
rwdemois shown. - Calls RSC.execute() to run
the DataBasic subroutine.
When the
RealWebUrlobject is created, the subroutine name is placed inURL.command.HttpServletRequestprovides methods to extract the query string and the servlet path, which are used as the two input parameters to RW.SAMPLE. When executed, RW.SAMPLE returns these two parameters to the browser, displaying, for example:First parameter is a query
Second parameter is /servlet/rwdemodoGet()
doGet() does the following:
- Uses methods provided by
HttpServletResponseto set the content type for the response and to get an output stream. - Creates an HTML page header to display the text
RealWeb Demo Servlet. In addition to building the HTML page header, the servlet could use methods provided byHttpServletRequestto build an HTML form requesting input from the user and append this input to the URL, to be passed as parameters to RW.SAMPLE. In this example, parameters to be passed to the subroutine are entered as part of the URL. - Creates an instance of the
RealWebUrl
class,
splitting up the different
sections of the calling URL and putting the information into the following usable
fields:
pathInfo the rest of the path after the servlet name;
debug set to true if the first path component contains
Debug(see Debugging);section the first path component following servlet name, or the
Debugkeyword;command the second path component following servlet name, or the
Debugkeyword;page the third path component following servlet name, or the
Debugkeyword - Calls
RealWeb.getConnectionto get a connection to the database. This will return a current connection or create a new one. TheRealWebclass extendsRSCConnection, so making available the methods withinRSCConnection. - Calls the local
execute()method (see later code) to execute the Remote Basic subroutine. - Makes the connection available again.
- Completes the HTML page.