Java web

<div class="output_wrapper" id="output_wrapper_id" style="font-size: 15px; color: rgb(62, 62, 62); line-height: 1.8; word-spacing: 2px; letter-spacing: 2px; font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center center;"><h3 id="h1ajax" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">1.Ajax</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">AJAX = Asynchronous JavaScript and XML(异步 JavaScript 和 XML)。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Ajax 的原理简单来讲经过 XmlHttpRequest 对象来向服务器发异步请求,从服务器得到数据,而后用 Javascript 来操做 DOM 而更新页面。这其中最关键的一步就是从服务器得到请求数据。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">XmlHttpRequest 是 ajax 的核心机制,它是在 IE5 中首先引入的,是一种支持异步请求的技术。简单的说,也就是 Javascript 能够及时向服务器提出请求和处理响应,而不阻塞用户。达到无刷新的效果</p> <figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="https://upload-images.jianshu.io/upload_images/11243907-fe16c2febe6b3660.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png" title="image.png" style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">image.png</figcaption></figure> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"></p> <h3 id="h2jquery" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">2.JQuery</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">JQuery 是一个 JavaScript 库。功能包括 HTML 元素选取和操做、CSS 操做、HTML 事件函数、 JavaScript 特效和动画、HTML DOM 遍历和修改、AJAX 和 Utilities。除此以外,JQuery 还提供了大量插件。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">基础语法: $(selector).action()。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">选择器:主要分四大选择器,分别是基本选择器、层次选择器、过滤选择器、属性过滤选择器。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">事件:例如 click()、dblclick()、mouseenter()、mouseleave()、mousedown()等。</p> <h3 id="h3cookie" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">3.Cookie</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">在 web 程序中是使用 HTTP 协议来传输数据的,由于 http 是无状态协议,一旦数据交换完毕,客户端和服务器端的链接就会关闭,再次交换数据须要创建新的链接,因此没法实现会话跟踪,cookie 技术则弥补了这一缺陷。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 实际上一段的文本信息,客户端请求服务器。若是服务器须要记录该用户的状态,就使用 response 向客户端浏览器颁发一个 cookie。客户端浏览器会把 cookie 保存起来。当浏览器再请求该网站时,浏览器把请求的网址连同该 cookie 一同提交给服务器。服务器检查该 cookie,以此来辨认用户的状态。服务器还能够根据须要修改 cookie 的内容。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 生命周期:</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 的 maxAge 决定 cookie 的生命周期,单位为秒(second)。cookie 经过 getMaxAge() 方法和 setMaxAge()方法来得到 maxAge 属性,若是 maxAhe 属性为正,则表示 cookie 会在 maxAge 秒以后自动失效。若是 maxAge 属性为负,则说明 cookie 仅在本浏览器窗口和本窗口打开的子窗口下有效,关闭窗口 cookie 则失效。maxAge 的默认值是-1 当 maxAge 的值为 0 时,表示删除 cookie。</p> <h3 id="h4session" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">4.Session</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 也是一种记录客户状态的机制,不一样的是 cookie 保存在客户端浏览器中,而 session 保存在服务器上。客户端浏览器访问服务器是时候把客户端信息以某种形式记录在服务器上,这就是 session 中查找该客户的状态。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 生命周期:</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 保存在服务器端,为了得到更高的存取速度,服务器通常把 session 放在内存。每一个用户都会有一个独立的 session,若是 session 内容过于复杂,当大量客户访问服务器时可能会致使内存溢出。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 在用户第一次访问服务器的时候自动建立,须要注意只有访问 JSP,Servlet 等程序时才会建立 session;只要访问 HTML、IMAGE 等静态资源不会建立 session。若是还没有生成session,可使用 request.getSession(true)强制生成 session。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">在建立了Session的同时,服务器会为该Session生成惟一的Session id,而这个Session id在随后的请求中会被用来从新得到已经建立的Session</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 生成后,只要用户访问,服务器就会更新 session 的最后访问时间,并维护该 session。用户每访问服务器一次,不管是否续写 session 服务器都认为该用户的 session 活跃(active)了一次。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Session 对应的类是 javax.servlet.http.HttpSession,每个访问者都对应一个 session 对象,并将其状态信息保存在这个 session 对象中,session 对象的建立是在用户第一次访问服务器时产生的。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">可是服务端的session的实现对客户端的cookie有依赖关系的,上面我讲到服务端执行session机制时候会生成session的id值,这个id值会发送给客户端,客户端每次请求都会把这个id值放到http请求的头部发送给服务端,而这个id值在客户端会保存下来,保存的容器就是cookie,所以当咱们彻底禁掉浏览器的cookie的时候,服务端的session也会不能正常使用</p> <h3 id="h5forwardredirect" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">5.转发(forward)和重定向(redirect)的区别?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">转发是服务器行为,重定向是客户端行为。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">forward(转发) 是容器中控制权的转向,是服务器请求资源,服务器直接访问目标地址的 URL,把那个 URL 的响应内容读取过来,而后把这些内容再发给浏览器,浏览器根本不知道服务器发送的内容是从哪儿来的,因此它的地址栏中仍是原来的地址。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">redirect(重定向) 就是服务器端根据逻辑,发送一个状态码,告诉浏览器从新去请求那个地址,所以从浏览器的地址栏中能够看到跳转后的连接地址,很明显 redirect 没法访问到服务器保护起来资源,可是能够从一个网站 redirect 到其余网站。</p> <ol style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: decimal;"> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">从地址栏显示来讲: forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,而后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,因此它的地址栏仍是原来的地址. redirect是服务端根据逻辑,发送一个状态码,告诉浏览器从新去请求那个地址.因此地址栏显示的是新的URL.</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">从数据共享来讲: forward:转发页面和转发到的页面能够共享request里面的数据. redirect:不能共享数据.</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">从运用地方来讲: forward:通常用于用户登录的时候,根据角色转发到相应的模块. redirect:通常用于用户注销登录时返回主页面和跳转到其它的网站等</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">从效率来讲: forward:高. redirect:低.</p></li> </ol> <h3 id="h6" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">6.怎么防止表单重复提交?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">i.禁掉提交按钮。表单提交后使用 Javascript 使提交按钮 disable。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">ii.Post/Redirect/Get 模式。在提交后执行页面重定向,这就是所谓的 Post-Redirect-Get (PRG) 模式。简言之,当用户提交了表单后,你去执行一个客户端的重定向,转到提交成功信息页面。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">iii.在 session 中存放一个特殊标志。当表单页面被请求时,生成一个特殊的字符标志串,存在 session 中,同时放在表单的隐藏域里。接受处理表单数据时,检查标识字串是否存在,并当即从 session 中删除它,而后正常处理数据。</p> <h3 id="h7webxml" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">7.web.xml 文件中能够配置哪些内容?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">web.xml 用于配置 Web 应用的相关信息,如:监听器(listener)、过滤器(filter)、 Servlet、相关参数、会话超时时间、安全验证方式、错误页面等</p> <h3 id="h8servlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">8. servlet声明周期?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Initialization 初始化</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Service 服务</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Distory 销毁</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.init()。当Servlet第一次被装载时,Servlet引擎调用这个Servlet的init()方法,只调用一次。若是某个Sevlet须要特殊的初始化须要。那么Servlet编写人员能够重写该方法来执行初始化任务。若是某个Servlet不须要初始化,那么默认状况下将调用它父类的init方法。系统保证,在init方法成功完成之前,是不会调用Servlet去处理任何请求的。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">2.service()。这是Servlet最重要的方法,是真正处理请求的地方。对于每一个请求,Servlet引擎将调用Servlet的service方法,并把Servlet请求对象和Servlet响应对象最为参数传递给它。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">3.destroy()。这是相对于init的可选方法,当Servlet即将被卸载时由Servlet引擎来调用,这个方法用来清除并释放在init方法中所分配的资源</p> <h3 id="h9jspweb" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">9.Jsp类置对象(Web开发中的四个域对象)</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">范围小到大:<br> page(jsp有效) page域指的是pageContext.<br> request(一次请求) request域指的是request HttpServletRequest<br> session(一次会话) session 域指的是 session HTTPSession<br> application(当前web应用) application 域指的是 application ServletContext</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">4个对象的生命周期(生命周期就是值对象的建立到销毁的期间):<br> page:jsp页面被执行,生命周期开始,jsp页面执行完毕,声明周期结束。<br> request:用户发送一个请求,开始,服务器返回响应,请求结束,生命周期结束。<br> session:用户打开浏览器访问,建立session(开始),session超时或被声明失效,该对象生命周期结束。<br> application:web应用加载的时候建立。Web应用被移除或服务器关闭,对象销毁。【结束】<br>appliction: ServletContext<br>session: HttpSession<br>request: HttpServletRequest<br>response:HttpServletResponse<br>pageContext: PageContext<br>out: JspWriter<br>config: ServletConfig<br>page: this</p> <h3 id="h10dogetdopost" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">10.doGet 和doPost区别</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">get方式将参数放在url后面,在请求行, post方式将参数放在请求的正文部分。<br>get方式参数显示在地址栏,不安全, post参数地址栏不可见,相对安全。<br>地址栏的参数长度有限制,post无限制<br>若是未重写service()方法,则执行父类的service()方法,起调度做用,若是是get请求就调动doGet()若是是post请求就调用doPost()<br>若是重写了service()方法,即便重写了doGet()或doPost()也只会调用service()方法</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">3.提交数据的安全<br>POST比GET方式的安全性要高<br>经过GET提交数据,用户名和密码将明文出如今URL上,由于一下几个缘由get方式安全性会比post弱:<br>(1)登陆页面有可能被浏览器缓存<br>(2)其余人查看浏览器的历史纪录,那么别人就可 以拿到你的帐号和密码了<br>(3)当赶上跨站的攻击时,安全性的表现更差了</p> <h3 id="h11http" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">11.HTTP协议下请求和响应的格式</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">请求格式:请求行 请求头 请求正文部分<br>响应格式:响应状态行 响应头 响应内容</p> <h3 id="h12requestgetattributerequestgetparameter" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">12. request.getAttribute() 和 request.getParameter() 有何区别?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">request.getAttribute()是获取属性值<br>request.getParameter()是得到请求中值</p> <h3 id="h13servletfilter" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">13.Servlet和Filter的区别:</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">整的流程是:Filter对用户请求进行预处理,接着将请求交给Servlet进行处理并生成响应,最后Filter再对服务器响应进行后处理。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Filter有以下几个用处:<br>Filter能够进行对特定的url请求和相应作预处理和后处理。<br>在HttpServletRequest到达Servlet以前,拦截客户的HttpServletRequest。<br>根据须要检查HttpServletRequest,也能够修改HttpServletRequest头和数据。<br>在HttpServletResponse到达客户端以前,拦截HttpServletResponse。<br>根据须要检查HttpServletResponse,也能够修改HttpServletResponse头和数据。<br>实际上Filter和Servlet极其类似,区别只是Filter不能直接对用户生成响应。实际上Filter里doFilter()方法里的代码就是从多个Servlet的service()方法里抽取的通用代码,经过使用Filter能够实现更好的复用。</p> <h3 id="h14filterservlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">14. Filter和Servlet的生命周期</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.Filter在web服务器启动时初始化<br>2.若是某个Servlet配置了 1 ,该Servlet也是在Tomcat(Servlet容器)启动时初始化。<br>3.若是Servlet没有配置1 ,该Servlet不会在Tomcat启动时初始化,而是在请求到来时初始化。<br>4.每次请求, Request都会被初始化,响应请求后,请求被销毁。<br>5.Servlet初始化后,将不会随着请求的结束而注销。<br>6.关闭Tomcat时,Servlet、Filter依次被注销。</p> <h3 id="h15jspservlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">15. Jsp与Servlet区别</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.JSP的本质就是Servlet,JSP页面在执行的时候都会被服务器端的JSP引擎转换为Servelet(.java),而后又由JSP引擎调用Java编译器,将Servelet(.java)编译为Class文件(.class),并由Java虚拟机(JVM)解释执行。<br>2.Servlet中没有内置对象,Jsp中的内置对象都是必须经过HttpServletRequest对象,HttpServletResponse对象以及HttpServlet对象获得。<br>3.Servlet在Java代码中经过HttpServletResponse对象动态输出HTML内容,JSP在静态HTML内容中嵌入Java代码,Java代码被动态执行后生成HTML内容。<br>4.JSP侧重于界面表现,Servlet主要用于控制逻辑</p> <h3 id="h16servlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">16.Servlet的调用过程</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.浏览器输入访问路径后,携带了请求行,头,体<br>2.根据访问路径找到已注册的servlet名称<br>3.根据映射找到对应的servlet名<br>4.根据根据servlet名找到咱们全限定类名,既咱们本身写的类<br>5.服务器找到全限定类名后,经过反射建立对象,同时也建立了servletConfig,里面存放了一些初始化信息(注意服务器只会建立一次servlet对象,因此servletConfig也只有一个)</p> <h3 id="h18httphttps" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">18. HTTP与HTTPS有什么区别?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"> HTTP协议传输的数据都是未加密的,也就是明文的,所以使用HTTP协议传输隐私信息很是不安全,为了保证这些隐私数据能加密传输,因而网景公司设计了SSL(Secure Sockets Layer)协议用于对HTTP协议传输的数据进行加密,从而就诞生了HTTPS。简单来讲,HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,要比http协议安全。</p></div>java

相关文章
相关标签/搜索