ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/sec/sechttpsx.htm

84 lines
2.6 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: HTTPS servlet</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h6><a name="sechttpsex"></a>Example: HTTPS servlet</h6>
<pre>/*
* This material contains programming source code for your
* consideration. These examples have not been thoroughly
* tested under all conditions. IBM, therefore, cannot
* guarantee or imply reliability, serviceability, or function
* of these program. All programs contained herein are
* provided to you &quot;AS IS&quot;. THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* ARE EXPRESSLY DISCLAIMED. IBM provides no program services for
* these programs and files.
*/
import java.io.DataInputStream;
import java.security.*;
import java.net.URLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HttpsSampleServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) {
res.setContentType(&quot;text/html&quot;);
// url passed in as browser query string
String url = req.getParameter(&quot;httpsURL&quot;);
if (null != url)
url = URLDecoder.decode(url);
else {
// url passed in as servlet init parameter
url = getInitParameter(&quot;httpsURL&quot;);
}
URLConnection conn = null;
URL connectURL = null;
// send result to the caller
try {
PrintWriter out = res.getWriter();
if (null == url || url.length() == 0) {
out.println(&quot;No Https URL provided to retrieve&quot;);
}
else {
connectURL = new URL(url);
conn = connectURL.openConnection();
DataInputStream theHTML = new DataInputStream(conn.getInputStream());
String thisLine;
while ((thisLine = theHTML.readLine()) != null) {
out.println(thisLine);
}
}
out.flush();
out.close();
}
catch (Exception e) {
System.out.println(&quot;Exception in HttpsSampleServlet: &quot; + e.getMessage());
e.printStackTrace();
}
}//end goGet(...)
}//end class</pre>
</body>
</html>