分类: Java
2010-11-02 14:21:17
public
class ServletSample extends HttpServlet { // 第一步: 扩展 HttpServlet
抽象类。
public void doGet (HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException
{ // 第二步:重写doGet()方法
String myName = "";
// 第三步:获取HTTP 请求信息
java.util.Enumeration keys = request.getParameterNames();
while (keys.hasMoreElements());
{
key = (String) keys.nextElement();
if (key.equalsIgnoreCase("myName"))
myName = request.getParameter(key);
}
if (myName == "")
myName = "Hello";
// 第四步:生成 HTTP 响应。
response.setContentType("text/html");
response.setHeader("Pragma",
"No-cache");
response.setDateHeader("Expires",
0);
response.setHeader("Cache-Control",
"no-cache");
out.println(" "
+ myName + ", this is a very basic servlet that writes
an HTML For
instructions on running those samples on your WebSphere应用服务器,
"+
out.println("");
out.println("Just
a basic servlet
");
out.println ("
page.");
out.println ("
"open the page:");
out.println("");
out.println("where your.server.name
is the hostname of your WebSphere应用服
务器.");
out.println("