75 lines
2.2 KiB
HTML
75 lines
2.2 KiB
HTML
|
<!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>Troubleshoot by problem</title>
|
||
|
</head>
|
||
|
<BODY>
|
||
|
<!-- Java sync-link -->
|
||
|
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
||
|
|
||
|
|
||
|
<h5><A NAME="sampserv"></A>ServletSample.java</h5>
|
||
|
|
||
|
// ServletSample.java
|
||
|
|
||
|
<pre>
|
||
|
// Step 1: Add the necessary import statements.
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.*;
|
||
|
import javax.servlet.*;
|
||
|
import javax.servlet.http.*;
|
||
|
|
||
|
|
||
|
// Step 2: Extend HttpServlet.
|
||
|
|
||
|
public class ServletSample extends HttpServlet
|
||
|
{
|
||
|
|
||
|
// Step 3: Specify the required methods.
|
||
|
|
||
|
public void doGet (HttpServletRequest request, HttpServletResponse response)
|
||
|
throws ServletException, IOException
|
||
|
{
|
||
|
|
||
|
// Step 4: Get the HTTP request information, if any.
|
||
|
|
||
|
Enumeration keys;
|
||
|
String key;
|
||
|
String myName = "";
|
||
|
keys = request.getParameterNames();
|
||
|
while (keys.hasMoreElements())
|
||
|
{
|
||
|
key = (String) keys.nextElement();
|
||
|
if (key.equalsIgnoreCase("myName")) myName = request.getParameter(key);
|
||
|
}
|
||
|
System.out.println("Name = ");
|
||
|
if (myName == "") myName = "Hello";
|
||
|
|
||
|
|
||
|
// Step 5: Create the HTTP response.
|
||
|
|
||
|
response.setContentType("text/html");
|
||
|
response.setHeader("Pragma", "No-cache");
|
||
|
response.setDateHeader("Expires", 0);
|
||
|
response.setHeader("Cache-Control", "no-cache");
|
||
|
|
||
|
PrintWriter out = response.getWriter();
|
||
|
out.println("<html>");
|
||
|
out.println("<head><title>Just a basic servlet</title></head>");
|
||
|
out.println("<body>");
|
||
|
out.println("<h1>Just a basic servlet</h1>");
|
||
|
out.println ("<p>" + myName + ", this is a very basic servlet.");
|
||
|
out.println("</body></html>");
|
||
|
out.flush();
|
||
|
}
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|