Java/Web Manual
  SoftPLC    Font size:      

Servlets

A Weblet is an HTTP server running under SoftPLC. SoftPLC Weblets support the JavaSoft Servlet API. Servlets are dynamically loaded Java code fragments that get invoked on demand by a client side web browser, but actually run in the server. For a tutorial on Servlets, see:

http://java.sun.com/docs/books/tutorial/servlets/index.html

The web browser actually has no idea it is doing this, but depending on the URL that is requested, a different Servlet is invoked on the server in response to a particular URL. SoftPLC supports an unlimited number of Servlets.

User's may write their own Servlets to handle any number of activities on the server side. The Servlet API is documented in the SoftPLC Java Toolkit as well as on the Sun website.

This manual is not intended to be a programming manual. There are plenty of skilled developers in this field of server side development, as there are over 5,000 websites being added to the Internet each day.

Uses for Servlets

Servlets can dynamically create web pages that contain live data. They are also very useful for processing form data that was entered into a web browser page.

They are also used as a partnering agent to interact with network transactions of any kind initiated by client side Applets. A common scenario will use an Applet to process a series of data entry screens, and at completion this data is sent to a URL on the server using the HTTP POST request. The URL is carefully chosen so that the request gets routed to a Servlet that has been specially written to handle data in the format created by the Applet on the other end of the wire.

Servlets may write to disk, so there is almost no limit to what they can perform.

Invoking a Servlet

The client web browser may invoke a Servlet by referencing a URL (either manually keyed in, or occurring as a hyperlink), that contains the basic form:

http://<ipaddress>/servlet/<servletname>

Examples:

http://softplc1/servlet/ShiftReportwould invoke the Servlet "ShiftReport" on the box whose IP Address is softplc1
http://130.1.1.155/servlet/com/company/Servletwould invoke the Servlet implemented by class "com.company.Servlet" on the box whose IP Address is 130.1.1.155

Another way to invoke a servlet is to add an entry to the \LST\USR\SERVLET.LST file so that the servlet is tied to a particular file extension. Here is an example for the SmartPage servlet:

ServletByRequest(GET|*|stp): SmartPage

This causes any URI that ends in .stp to invoke SmartPage. See the comments in SERVLET.LST for more info.

Symbolic IP Addresses

There are two forms for IP addresses, numeric or symbolic. An example of a numeric IP address is 130.1.1.55 and an example of a symbolic IP address is softplc1, each shown in the table above.

In order to use a symbolic IP address, sometimes called a domain name, you must have a Domain Name Server (DNS) somewhere on your network, and the lookup table in the DNS must have an entry which maps your symbolic name to its numeric IP address. Many UNIX boxes have this capability and NT server does too. If you have lots of browser clients, this is the most maintainable scheme to use.

For single client environments, or in the event you don’t have a DNS, you can edit the text of your "HOSTS" file on your local disk. On WinNT the file is C:\WIN32\SYSTEM32\HOSTS. On WinXP and higher, the file is C:\WINDOWS\SYSTEM32\drivers\etc\hosts. The file HOSTS.SAM can be copied to HOSTS and then simply add your symbolic entries there.

Query Strings

By using query strings that may be tacked onto the end of URL’s, any given Servlet can respond in different ways. A query string has a series of <name>=<value> pairs, each separated by the '&' character. As an example URL, consider:

http://softplc1/servlet/mydata?address=S23&length=4

Query strings are always introduced at the end of a URL by a question mark character ‘?’. So in this example there are two name/value pairs: "address=S23" and "length=4".

Query strings are normally generated by the web browser as the result of processing an HTML form.