getPara("title");//返回页面提交表单里name是title的参数值
getPara(0);//返回url请求中urlPara参数的第一个值,比如localhost:/test/method/v0-v1-v2 我们会返回v0
getPara();//返回url请求中urlPara的参数组整体 比如返回v0-v1-v2
约定用N或n来表示urlPara中的负号 获取时使用getParaToInt()
当urlPara中使用中文时,会出现乱码
<form action="/user/save/n1-n2-a-32-ada-中文-2" method="post"> <input name="user.acc_username" type="text"> <input name="user.acc_password" type="text"> <input name="testGetPara" type="text"> <input name="testGetPara" type="text"> <input type="submit"> </form>
检查一下这几个地方的设置:
1:页面有没有设置 < meta http-equiv="content-type" content="text/html; charset=utf-8" >
2:configConstants 中有没有设置成 me.setEncoding("utf-8");
3:需要使用表单域传参,而不是 url 中的问号挂参,因为 url 问号挂参的编码方式与 tomcat、jetty 配置有关
4:数据库的 jdbcUrl 连接中的字符集设置是不是 utf-8。(这项对于本问题无关,但对于其它情况下的乱码有关)
依然不行的话,用
System.out.println(URLDecoder.decode(getPara(5),"UTF-8"));
或者 更改传参的方式
/user/save/n1-n2-a-32-ada?zhongwen=中文
就ok了
提交表单中的数据有数组
就是你有几个相同name的input 提交时,使用getPara()获取不了数组
String[] values = getRequest().getParameterValues("testGetPara");
String[] values = getParaMap().get("testGetPara");