要点以及遇到的问题:
1.代理模式增强功能
2.request.getParameterMap,底层源码给map加锁.map得值不可修改
3.解决:值放置到数组中时,遍历数组可修改.
注意:不能随便使用迭代器遍历修改.
引用数组修改的是内存地址中的实际参数,而for循环里面的局部变量为实际参数的副本,
修改其值不会修改实际的值
1 | //过滤器 |
//test1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42package com.fzq.web.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@WebServlet("/testServlet")
public class TestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/* String name = request.getParameter("name");
String msg = request.getParameter("msg");
System.out.println(name+":"+msg);*/
//map
Map<String, String[]> map = request.getParameterMap();
for (Map.Entry<String, String[]> entry : map.entrySet()) {
String name = entry.getKey();
String[] msg = entry.getValue();
System.out.println(name+":"+msg[0]);
}
/*
String name = request.getParameterValues("name")[0];
String msg = request.getParameterValues("msg")[0];
System.out.println(name+":"+msg);
*/
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}