servletContext().getRealPath待整理,年久失修的笔记

servletContext().getRealPath是获取本机服务器的项目所在的路径,并不是获取用户客户端的缓存路径。这点传智播客_超全面的JavaWeb视频教程vedio day08 第17个视频明显阐述有问题。明显post请求和get请求

GET /hello3/index.jsp HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, /
**Accept-Language: zh-CN,en-US;q=0.5
*****User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
***Host: localhost
Connection: Keep-Alive

请求行(请求方式 请求路径 协议/版本)
多个请求头信息:头名称:头值
空行
请求体


*****HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=48F75E08BD4DF3C3E72919543CBFDF81; Path=/hello3/; HttpOnly
*响应内容的MIME类型:Content-Type: text/html;charset=ISO-8859-1
Content-Length: 646
Date: Thu, 22 May 2014 06:45:26 GMT

响应行(协议/版本 状态码 状态码的解析)
响应头(key/value格式)
空行
响应正文




<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->


This is my JSP page.

Hello – 3



======================================

POST /index.jsp HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, /
Referer: http://localhost/day08_1/login.html
Accept-Language: zh-CN,en-US;q=0.5
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
*****Content-Type: application/x-www-form-urlencoded –> 表示表单中的数据会自动使用url来编码!
Accept-Encoding: gzip, deflate
Host: localhost
Content-Length: 30
Connection: Keep-Alive
Cache-Control: no-cache

username=zhangsan&password=123

正文(体),表单是一大堆内容,而发送给服务器的只有一行字符串!

username=%E5%BC%A0%E4%B8%89&password=123

-128~127、-128~127、-128~127、-128~127、-128~127、-128~127

字节+128 –> 转换成16进制 –> 添加%这个前缀
36 –> %A4

这些信息里面是没有任何关于客户端路径的传输的
/E:/Apache-tomcat/apache-tomcat-7.0.53/wtpwebapps/demo/WEB-INF/classes/
到这里应该可以看出来其实
/E:/Apache-tomcat/apache-tomcat-7.0.53/wtpwebapps/demo/

明显上述的路径包含了服务器tomcat的路径

明显的webapplication项目有个特点,就是eclipse中你只要部署了,以后只要保存,class文件会自动保存到tomcat的wepapps目录下面的项目目录下。但是你必须重启tomcat才能够让代码生效。这点没有验证过intellij是不是也是这样的。以后反正我会用intellij来写后台,接口应该使用servlet来写,jsp估计是独立的前端应用应该写两个webapp便于管理

猜你喜欢

转载自blog.csdn.net/arios171/article/details/72650410