怎么让request.getrequestedsessionid 是空值
答案:2 悬赏:10 手机版
解决时间 2021-02-01 11:56
- 提问者网友:咪咪
- 2021-02-01 07:44
怎么让request.getrequestedsessionid 是空值
最佳答案
- 五星知识达人网友:鸠书
- 2021-02-01 08:19
去的是从客户端带来的session的id号 session由cookie放入客户端 所以第一次发起请求时 这个值为空因为客户端没有cookie
全部回答
- 1楼网友:孤独入客枕
- 2021-02-01 08:45
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("
");
//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 locales = request.getLocales();
while(locales.hasMoreElements()){
Locale temp = locales.nextElement();
println("\n Locales = " + temp);
}
//7. 接收请求 Internet Protocol (IP) 接口主机名
String localName = request.getLocalName();
println("localName = " + localName);
//8. 接收请求接口 Internet Protocol (IP) 端口号
int localPort = request.getLocalPort();
println("localPort = " + localPort);
//9. 返请求使用协议名称版本
String protocol = request.getProtocol();
println("protocol = " + protocol);
//10. 读取请求文信息
BufferedReader reader = request.getReader();
println("getReader = " + reader.toString());
//11. 发送请求客户端
String remoteAddr = request.getRemoteAddr();
println("RemoteAddr = " + remoteAddr);
//12. 发送请求客户主机
String remoteHost = request.getRemoteHost();
println("RemoteHost = " + remoteHost);
//13. 发送请求客户主机端口
int remotePort = request.getRemotePort();
println("RemotePort = " + remotePort);
//14. 返用于发请求案名称例:http 、 https 、 ftp
String scheme = request.getScheme();
println("Scheme = " + scheme);
//15. 返请求发送服务器主机名Host值":"()前部值 或者解析服务器名称或服务器IP址
String serverName = request.getServerName();
println("ServerName = " + serverName);
//16. 返请求发送端口"Host"值":" ()部值或者接受客户端连接服务器端口
int serverPort = request.getServerPort();
println("ServerPort = " + serverPort);
//17. 返boolean值指示请求否使用安全通道(比HTTPS) 发
boolean secure = request.isSecure();
println("isSecure = " + secure);
// ServletRequest 接口提供
// HttpServletRequest 接口提供
String authType = request.getAuthType();
println("authType = " + authType);
//19. getDateHeader ??
request.getDateHeader("");
//20. 返请求包含所名称枚举
Enumeration headerNames = request.getHeaderNames();
println("");
while(headerNames.hasMoreElements()){
String name = headerNames.nextElement();
println(" headerNmea = " + name + "; getHeader = " + request.getHeader(name));
}
println("");
//21. int形式返指定请求值 ???
request.getIntHeader("123");
//22. 返与客户端发请求发送URL相关联额外路径信息
String pathInfo = request.getPathInfo();
println("PathInfo = " + pathInfo);
//23. 返包含请求RUL路径面查询字符串没查询字符串返null
String remoteUser = request.getRemoteUser();
println("RemoteUser = " + remoteUser);
//24. 返客户端制定ID
String requestedSessionId = request.getRequestedSessionId();
println("requestSessionId = " + requestedSessionId);
//25. 返请求调用servletURL部
String servletPath = request.getServletPath();
println("servletPath = " + servletPath);
//26. 返与请求关联前HttpSession没前并且参数true,则返新
HttpSession session = request.getSession(true);
println("getSession(true) = " + session);
//27. 返包含前已经验证用户名称java.security.Principal象用户没经验证则该返null
Principal userPrincipal = request.getUserPrincipal();
println("userPrincipal = " + userPrincipal);
//28. 检查id否作Cook进入
boolean sessionIdFromCookie = request.isRequestedSessionIdFromCookie();
println("sessionIdFromCookie = " + sessionIdFromCookie);
//29. 检查请求ID否作请求URL部进入
boolean sessionIdFromURL = request.isRequestedSessionIdFromURL();
println("sessionIdFormURL = " + sessionIdFromURL);
//30.
println("");
out.flush();
out.close();
}
public void println(Object obj){
this.response.setContentType("text/html;charset=utf-8");
try {
out.println("1. ");
out.println(obj);
out.println("\n");
} catch (Exception e) {
e.printStackTrace();
}
}
2. 运行结
getCharacterEncoding = utf-8
getContentLength = -1
getContentType = null
getLocalAddr = 127.0.0.1
getLocale = zh_CN
Locales = zh_CN
Locales = zh
Locales = en_US
Locales = en
localName = lm.licenses.adobe.com
localPort = 8080
protocol = HTTP/1.1
getReader = org.apache.catalina.connector.CoyoteReader@17b8d3d
RemoteAddr = 127.0.0.1
RemoteHost = 127.0.0.1
RemotePort = 57814
Scheme = http
ServerName = localhost
ServerPort = 8080
isSecure = false
authType = null
headerNmea = host; getHeader = localhost:8080
headerNmea = user-agent; getHeader = Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20110101 Firefox/32.0
headerNmea = accept; getHeader = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
headerNmea = accept-language; getHeader = zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
headerNmea = accept-encoding; getHeader = gzip, deflate
headerNmea = cookie; getHeader = JSESSIONID=30256CEB48E2BF6050BF6E122635EAC4
headerNmea = connection; getHeader = keep-alive
PathInfo = null
RemoteUser = null
requestSessionId = 30256CEB48E2BF6050BF6E122635EAC4
servletPath = /req
getSession(true) = org.apache.catalina.session.StandardSessionFacade@1fcf1ba
userPrincipal = null
sessionIdFromCookie = true
sessionIdFormURL = false
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯