日期:2014-05-20  浏览次数:20747 次

为什么不执行doget
package com.michael.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import java.util.Enumeration;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServletBasic extends HttpServlet {
  // private static final String CONTENT_TYPE = "text/html; charset=GBK";

  /* public void init(ServletConfig config) throws ServletException {
  super.init(config);
  }
*/
  public ServletBasic() {
  super();
  System.out.println("----ServletBasic-----");
  }

  public void destroy() {
  super.destroy();
  System.out.println("----destroy-----");
  }

  public void doGet(HttpServletRequest request, 
  HttpServletResponse response) throws ServletException, 
  IOException {
  // System.out.println("----doget-----");  
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  System.out.println("username=" + username);
  if (username != null && username.equals("redking")) {
  request.getRequestDispatcher("/successful.html").forward(request, 
  response);
  } else {
  request.getRequestDispatcher("/failure.html").forward(request, 
  response);
  }


  /* System.out.println("----doget-----");
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  out.println("<html>");
  out.println("<head><title>A Servlet</title></head>");
  out.println("<body>");
  out.println(" this is");
  out.println(this.getClass());
  out.println(",using the GET method");
  out.println("<p>The servlet has received a GET. This is the reply.</p>");
  out.println("<p>welcom to amaker!.</p>");
  out.println("</body></html>");
  out.close();*/
  }

  public void doPost(HttpServletRequest request, 
  HttpServletResponse response) throws ServletException, 
  IOException {
  System.out.println("----dopost-----");
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  out.println("<html>");
  out.println("<head><title>A Servlet</title></head>");
  out.println("<body>");
  out.println(" this is");
  out.println(this.getClass());
  out.println(",using the POST method");
  out.println("<p>The servlet has received a POST. This is the reply.</p>");
  out.println("</body></html>");
  out.close();
  }

  public void init() throws ServletException {
  //第一种方法