servlet request请求对象常用方法总结

发布网友 发布时间:2022-04-23 18:13

我来回答

1个回答

热心网友 时间:2022-05-05 01:31

1. request请求对象常用方法:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset = utf-8");
this.response = response;
out = this.response.getWriter();
println("<ol>");
//1. 获取请求方式、处理乱码问题
String method = request.getMethod();

//servletRequest中的方法
request.setCharacterEncoding("utf-8");
//1. 获取请求体的编码方式
String characterEncoding = request.getCharacterEncoding();
println("getCharacterEncoding = " + characterEncoding);

//2. get body length
int contentLength = request.getContentLength();
println("getContentLength = " + contentLength);

//3. MIME type
String mimeType = request.getContentType();
println("getContentType = " + mimeType);

//4. 接收请求的接口的 Internet Protocol (IP) 地址
String ip = request.getLocalAddr();
println("getLocalAddr = " + ip);

//5. 基于 Accept-Language 头,返回客户端将用来接受内容的首选 Locale 客户端语言环境
Locale locale = request.getLocale();
println("getLocale = " + locale);

//6. 所有的语言环境
Enumeration<Locale> locales = request.getLocales();
while(locales.hasMoreElements()){
Locale temp = locales.nextElement();
println("\n Locales = " + temp);
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com