package am_cn.itcsat.request; |
import java.io.IOException; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
/* |
* 获得 客户端 提交过来的 所有的 数据 |
* |
*/ |
public class RequestDemo1 extends HttpServlet { |
public void doGet(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException { |
// 要 干什么 |
|
// 解决 post 请求方式下的 乱码 |
request.setCharacterEncoding( "UTF-8" ); |
|
String name = request.getParameter( "name" ); |
String password = request.getParameter( "password" ); |
String gender = request.getParameter( "gender" ); |
// String hobbies = request.getParameter("hobbies"); // 爱好 这里 丢 数据了 |
String city = request.getParameter( "city" ); |
String description = request.getParameter( "description" ); |
|
System.out.println( "name : " + name); |
System.out.println( "password : " + password); |
System.out.println( "gender : " + gender); |
// System.out.println("hobbies : " + hobbies); |
System.out.println( "city : " + city); |
System.out.println( "description : " + description); |
|
System.out.println( "=============================" ); |
|
// 通过 这个 api 来 解决 提交的 某个 name 有多个值的 情况, 不会丢数据 . |
String[] parameterValues = request.getParameterValues( "hobbies" ); |
|
for (String value : parameterValues) { |
System.out.println( " value : " + value); |
} |
|
} |
public void doPost(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException { |
doGet(request, response); |
} |
} |