ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzatz_5.4.0.1/51/program/servpex.htm

54 lines
2.1 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Example: Extending PageListServlet</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h5><a name="servpex"></a>Example: Extending PageListServlet</h5>
<p>See the <a href="codex.htm">Code example disclaimer</a> for legal information about this code example.</p>
<p>This example shows how a servlet extends the PageListServlet class and determines the markup-language type required by the client. The servlet then uses the callPage() method to call an appropriate JavaServer Pages (JSP) file. In this example, the JSP file that provides the correct markup language for the response is Hello.page.</p>
<pre>public class HelloPervasiveServlet extends PageListServlet implements Serializable {
// doGet -- Process incoming HTTP GET requests
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// This is the name of the page to be called:
String pageName = &quot;Hello.page&quot;;
// First check if the servlet was invoked with a queryString that contains a
// markup-language value. For example, if the servlet is invoked with the URL
// http://localhost/servlets/HelloPervasive?mlname=VXML, use this method:
String mlname= getMLNameFromRequest(request);
// If no markup language type is provided in the queryString, then try to
// determine the client type from the request, and use the markup-language name
// configured in the client_types.xml file.
if (mlName == null) {
mlName = getMLTypeFromRequest(request);
}
try {
// Serve the request page.
callPage(mlName, pageName, request, response);
}
catch (Exception e) {
handleError(mlName, request, response, e);
}
}
}</pre>
</body>
</html>