Web Development


Appendix D. Using Java Servlets

A Panther web application can run as a Java servlet. For this feature, you need a servlet engine using Java Virtual Machine Version 1.1.5 or later with native thread support enabled.

Java servlets extend the functionality of a Java-enabled HTTP servers. They are server-side components which interact with servlet engines running on HTTP servers through requests and responses. For example, a client program running on a web browser sends a request to an HTTP server. This request is processed by the servlet engine that runs with the HTTP server. The HTTP server returns a response to the servlet which in turn sends a response in HTTP format to the client.

Java servlets are an alternative to CGI programs and to vendor-specific APIs, such as NSAPI or ISAPI. By being both platform-independent and threaded, Java servlets have advantages over other protocols.


Installing Java Servlet Support

The files for Java servlet support are located at WebInstallDir/servlet, as in /usr/panther/servlet on UNIX or C:\Prolifics\Panther\Servlet on Windows.

The servlet directory of your Panther web installation contains the following files:

To install Java servlet support:

  1. Add the location of proweb.jar to the servlet engine's CLASSPATH. You must specify the full path.
  2. Add the directory containing the file prowebjni.dll (libprowebjni.so on UNIX) to the servlet engine's PATH. Alternatively, on Windows you could copy prowebjni.dll to the Windows directory.
  3. Restart the servlet engine.

Accessing the Panther Web Application

To access the Panther web application using Java servlets:

  1. Start the Panther web application.Access the application using the following URL:
    http://HostName/proweb/WebAppName/ScreenName

    The following URL accesses the dstord.scr screen in the vidstore web application:

    http://myhost.com/proweb/vidstore/dstord.scr

Panther's Java Servlet Classes

Panther's Java servlet implementation extends the javax.servlet and the javax.servlet.http packages in the Java Servlet API.

The Java classes in proweb.jar include:

Methods

For more information on the following methods, refer to the Java Servlet API documentation at http://java.sun.com and to the HTML version of the Java class files.

Panther HTTP Servlet

The following methods are in ProlificsHttpServlet:

doGet
Passes the GET request to a Panther application.
public void doGet(HttpServletRequest req,  
HttpServletResponse res)
throws ServletException, IOException;
public void doGet(HttpServletRequest req,
HttpServletResponse res, String appname,
Boolean chunked)
throws ServletException, IOException;

doPost
Passes the POST request to a Panther application.
public void doPost(HttpServletRequest req,  
HttpServletResponse res)
throws ServletException, IOException;
public void doPost(HttpServletRequest req,
HttpServletResponse res, String appname,
Boolean chunked)
throws ServletException, IOException;

getServletInfo
Describes the servlet.
public String getServletInfo();init

If specified, it overrides the init method in the GenericServlet class which the servlet engine calls when the servlet is loaded.

public void init(ServletConfig config) 
	throws ServletException;

Servlet Requests

The following methods in the HttpServletRequest interface are used by ProlificsHttpServlet:

getAuthType
Gets the authentication scheme of this request. Same as the CGI variable AUTH_TYPE.
public String getAuthType();

getContentLength
Returns the size of the request entity data, or -1 if not known. Same as the CGI variable CONTENT_LENGTH.
public int getContentLength();

getContentType()
Returns the Internet Media Type of the request entity data, or null if not known. Same as the CGI variable CONTENT_TYPE.
public String getContentType();

getCookies
Gets the array of cookies found in this request.
public Cookie[] getCookies();

getHeader
Gets the value of the requested header field of this request.
public String getHeader(String name);

getHeaderNames
Gets the header names for this request.
public Enumeration getHeaderNames();

getInputStream
Returns an input stream for reading binary data in the request body.
public ServletInputStream getInputStream() 
	throws IOException;

getMethod
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made. Same as the CGI variable REQUEST_METHOD.
public String getMethod();

getPathInfo
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string. Same as the CGI variable PATH_INFO.
public String getPathInfo();

getPathTranslated
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string, and translates it to a real path. Similar to the CGI variable PATH_TRANSLATED.
public String getPathTranslated();

getProtocol
Returns the protocol and version of the request as a string in the form protocol/major version.minor version. Same as the CGI variable SERVER_PROTOCOL.
public String getProtocol();

getQueryString
Gets any query string that is part of the HTTP request URI. Same as the CGI variable QUERY_STRING.
public String getQueryString();

getRemoteAddr
Returns the IP address of the agent that sent the request. Same as the CGI variable REMOTE_ADDR.
public String getRemoteAddr();

getRemoteHost
Returns the fully qualified host name of the agent that sent the request. Same as the CGI variable REMOTE_HOST.
public String getRemoteHost();

getRemoteUser
Gets the name of the user making this request. The user name is set with HTTP authentication. Whether the user name will continue to be sent with each subsequent communication is browser-dependent. Same as the CGI variable REMOTE_USER.
public String getRemoteUser();

getRequestURI
Gets, from the first line of the HTTP request, the part of this request's URI that is to the left of any query string.
public String getRequestURI();

getServerName
Returns the host name of the server that received the request. Same as the CGI variable SERVER_NAME.
public String getServerName();

getServerPort
Returns the port number on which this request was received. Same as the CGI variable SERVER_PORT.
public int getServerPort();

getServletPath
Gets the part of this request's URI that refers to the servlet being invoked. Analogous to the CGI variable SCRIPT_NAME.
public String getServletPath();

There are additional methods included in FilterHttpServletRequest that are not called by ProlificsHttpServlet. See the HTML documentation for more information.

Servlet Responses

The following methods in the HttpServletResponse interface are used by ProlificsHttpServlet:

addCookie
Adds the specified cookie to the response. It can be called multiple times to set more than one cookie.
public void addCookie(Cookie cookie);

getOutputStream
Returns an output stream for writing binary response data.
public ServletOutputStream getOutputStream() 
throws IOException;

setContentLength
Sets the content length for this response.
public void setContentLength(int len);

setContentType
Sets the content type for this response.
public void setContentType(String type);

setHeader
Adds a field to the response header with the given name and value.
public void setHeader(String name, String value);

setStatus
Sets the status code, or the status code and message, for this response.
public void setStatus(int sc);
public void setStatus(int sc, String sm);

There are additional methods included in FilterHttpServletResponse that are not called by ProlificsHttpServlet. See the HTML documentation for more information.

Filter Servlet Input Stream

The following methods, if specified, override the methods in InputStream:

available
public int available() throws IOException;

close
public void close() throws IOException;

mark
public synchronized void mark(int readlimit);

markSupported
public boolean markSupported();

read
public int read() throws IOException;
public int read(byte buf[]) throws IOException;
public int read(byte buf[], int off, int len)
throws IOException;

readLine
public int readLine(byte buf[], int off, int len)
throws IOException
;

reset
public synchronized void reset() throws IOException;

Filter Servlet Output Stream

The following methods, if specified, override the methods in OutputStream or ServletOutputStream. See the HTML version of the class file for more information.

close
public void close() throws IOException;

flush
public void flush() throws IOException;

print
public void print(boolean bval) throws IOException;
public void print(char cval) throws IOException;
public void print(double dval) throws IOException;
public void print(float fval) throws IOException;
public void print(int ival) throws IOException;
public void print(long lval) throws IOException;
public void print(String sval) throws IOException;

println
public void println() throws IOException;
public void println(boolean bval) throws IOException;
public void println(char cval) throws IOException;
public void println(double dval) throws IOException;
public void println(float fval) throws IOException;
public void println(int ival) throws IOException;
public void println(long lval) throws IOException;

write
public void write(byte buf[]) throws IOException;
public void write(int val) throws IOException;
public void write(byte buf[], int off, int len)
throws IOException;