回覆列表
  • 1 # 使用者7063786766555

    HttpServletRequestgetParameter("username")取username值知道頁面表單項name表單資訊用getParameterNames

    package lintex;

    import javax.servlet.*;

    import javax.servlet.http.*;

    import java.io.*;

    import java.util.*;

    public class sss extends HttpServlet

    {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

    {

    response.setContentType("text/html;charset=gbk");

    PrintWriter out = response.getWriter();

    out.println("<form action=\"/getParameterNames/x\" method=post>使用者名稱:<INPUT TYPE=text NAME=username>password:<INPUT TYPE=text NAME=password>Email:<INPUT TYPE=text NAME=email><INPUT TYPE=submit></form>");

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

    {

    PrintWriter out = response.getWriter();

    String name;

    Enumeration test=request.getParameterNames();

    while(test.hasMoreElements())

    {

    name=(String)test.nextElement();

    out.println(name+"="+request.getParameter(name));

    out.println("<br>");

    }

    out.println();

    }

    }

    使用Enumeration需要匯入util包

  • 中秋節和大豐收的關聯?
  • 每個學生都必須要學習嗎?對此你有什麼看法?