公共接口类https教程ervletrequest继承自servletrequest.客户端浏览器发出的请求被封装成为一个httpservletrequest对象。所有的信息包括请求的地址,请求的参数,提交的数据,上传的文件客户端的ip甚至客户端操作系统都包含在其内。httpservletresponse继承了servletresponse接口,并提供了与http协议有关的方法
<%@ page import="java.util.*" %>
<%
string title = "httpservletrequest method values";
map entries = new treemap();
entries.put("getcharacterencoding", request.getcharacterencoding());
entries.put("getcontentlength", "" + request.getcontentlength());
entries.put("getcontenttype", request.getcontenttype());
entries.put("getlocale", request.getlocale());
entries.put("getprotocol", request.getprotocol());
entries.put("getremoteaddr", request.getremoteaddr());
entries.put("getremotehost", request.getremotehost());
entries.put("getscheme", request.getscheme());
entries.put("getservername", request.getservername());
entries.put("getserverport", "" + request.getserverport());
entries.put("issecure", "" + request.issecure());
request.setattribute("_table_title", title);
request.setattribute("_table_entries", entries);
out.println(request.getcharacterencoding());
%>
httpservletrequest方法总结
getscheme()方法返回请求的计划,比如http,https或者ftp.
getservername()方法返回被发送请求的服务器的主机名
getserverport()方法返回被发送请求的端口号。
getcontextpath()返回请求地址的根目录,以"/"开关,但不是以"/"结尾。
一个常用的获得服务器地址的连接字符串是:
string path = request.getcontextpath();
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
getcookies() 取得cookie
getmethod() 取得请求方法,如get,post或put
getrequesturl() 取得请求url(统一资源定位符)
getrequesturi() 取得请求uri(统一资源标识符)
getsession() 取得对应session
getheadernames()返回请求包含的所有头名称的一个enumeration(遍历器)
使用方法如下:
enumeration en = request.getheadernames();
while(en.hasmoreelements()){
out.print(en.nextelement());
}