創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
創(chuàng)新互聯(lián)公司是專業(yè)的樟樹網(wǎng)站建設(shè)公司,樟樹接單;提供成都網(wǎng)站建設(shè)、做網(wǎng)站,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行樟樹網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!Javaweb獲取表單數(shù)據(jù)的幾種方式
一、通過鍵值對的形式獲取表單數(shù)據(jù)
getParameter(String name):通過key,返回一個value。
getParameterValues(String name):通過key返回一個string數(shù)組(多個值)
getParameterNames():返回form表單中的所有key值。
下面介紹通過鍵值對獲取form表單數(shù)據(jù)的數(shù)據(jù)的方法:
@WebServlet({ "/FormServlet", "/form" }) public class FormServlet extends HttpServlet { private static final long serialVersionUID = 1L; public FormServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json;charset=utf-8"); PrintWriter out = response.getWriter(); EnumerationparamNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String name = paramNames.nextElement(); String[] values = request.getParameterValues(name); if(values!=null && values.length>0){ StringBuilder builder = new StringBuilder(); for (int i = 0; i < values.length; i++) { builder.append(values[i]+" "); } out.println(name+" : "+builder.toString()); } } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }