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

看下面程序,这个firstName和 lastName是怎么回事?
Source Code for Request Parameter Example

 import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RequestParamExample extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException
  {
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  out.println("<html>");
  out.println("<head>");
  out.println("<title>Request Parameters Example</title>");
  out.println("</head>");
  out.println("<body>");
  out.println("<h3>Request Parameters Example</h3>");
  out.println("Parameters in this request:<br>");
  if (firstName != null || lastName != null) {
  out.println("First Name:");
  out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
  out.println("Last Name:");
  out.println(" = " + HTMLFilter.filter(lastName));
  } else {
  out.println("No Parameters, Please enter some");
  }
  out.println("<P>");
  out.print("<form action=\"");
  out.print("RequestParamExample\" ");
  out.println("method=POST>");
  out.println("First Name:");
  out.println("<input type=text size=20 name=firstname>");
  out.println("<br>");
  out.println("Last Name:");
  out.println("<input type=text size=20 name=lastname>");
  out.println("<br>");
  out.println("<input type=submit>");
  out.println("</form>");
  out.println("</body>");
  out.println("</html>");
  }

  public void doPost(HttpServletRequest request, HttpServletResponse res)
  throws IOException, ServletException
  {
  doGet(request, response);
  }
}

------解决方案--------------------
lz你的程序不对哦。firstName和lastName,首先没有定义,其次都没有值,要从HttpServletRequest request中拿值的。