Servlet 的作用域(scope)
来源:互联网 发布:兴安数据库工程师招聘 编辑:程序博客网 时间:2024/06/05 01:03
TestScopeServlet.java
package com.tao.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class TestScopeServlet extends HttpServlet {/** * Constructor of the object. */public TestScopeServlet() {super();}/** * Destruction of the servlet. <br> */public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//request请求,请求结束作用域结束request.setAttribute("request_name", "Request_value");//session会话HttpSession session=request.getSession();session.setAttribute("session_name", "Session_value");//ServletContext请求,全局,所有用户共享的ServletContext cxt=this.getServletContext();cxt.setAttribute("servletContext_name", "servletContext_value");request.getRequestDispatcher("/servlet/ResultServlet").forward(request, response);}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */public void init() throws ServletException {// Put your code here}}
打开一个新窗口,request_value变成null,session_value和servletContext_value还在。
打开另一个浏览器,request_value和session_value变成null,servletContext_value还在。
0 0
- Servlet 的作用域(scope)
- 作用域(scope)
- Spring bean的作用域(scope)
- 名字的作用域(scope)
- JSP的scope作用域
- Spring的scope作用域
- angularjs scope(作用域)
- Web 四个作用域(scope)的用处
- Web 四个作用域(scope)的用处
- C/C++标识符的作用域(scope)小结
- mybatis的作用域(Scope)和生命周期
- Spring中Bean的作用域(Scope)
- AngularJS的scope变量的作用域
- Spring中bean的作用域scope
- 理解AngularJS的作用域Scope
- spring之bean的作用域scope
- spring中bean的scope(作用域)
- 如何使用spring的作用域scope
- JavaScript学习笔记(3)
- 黑马程序员-集合框架Collection的若干知识点
- Android利用JSON发送数据到服务器
- OSX文本编辑器代码
- java接口方法和类方法的区别 - 调用速度
- Servlet 的作用域(scope)
- MySQL的C++封装
- Android开发环境配置
- 深入理解Java Class文件格式(六)
- Java并发编程之线程管理(基本线程同步6)
- stm32之RS485
- 线段树扫描线面积并hdu1542
- <<The C Programming Language>>学习之路-练习题参考答案 1-4
- The database returned no natively generated identity value