表单post提交方式与得到
程序演示:
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 8 9 1040 41 4211 12 My JSP '4.jsp' starting page 13 14 15 16 17 18 19 22 23 24 25 26
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 8 9 1011 12 My JSP '5.jsp' starting page 13 14 15 16 17 18 19 22 23 24 25 26 <%27 request.setCharacterEncoding("UTF-8");28 out.print("用户名:"+request.getParameter("name")+"");29 out.print("性别:"+request.getParameter("sex")+"");30 String[] interest=request.getParameterValues("interesting");31 out.print("兴趣:"+"");32 for(String i:interest){33 out.print(i+"");34 }35 %>36 37
表单get提交方式与得到
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 8 9 1040 41 42 43 44 45 4611 12 My JSP '2.jsp' starting page 13 14 15 16 17 18 19 22 23 24 25 26
1 <%@page import="java.net.URLDecoder"%> 2 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 3 <% 4 String path = request.getContextPath(); 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 %> 7 8 9 10 1112 13 My JSP '3.jsp' starting page 14 15 16 17 18 19 20 23 24 25 26 27 <% //获取请求里包含的查询字符串28 String subStr=request.getQueryString();29 30 //使用urldecoder解码31 String codeStr=URLDecoder.decode(subStr, "UTF-8");32 //以&符号分解33 String[] spls=codeStr.split("&");34 35 for(String spl:spls){36 out.print(spl+"");37 38 }39 40 41 %>42 43 44 45 46