在servlet中获得application请求:ServletContext aplication = this.getServletContext();
在servlet中获得application请求:ServletContext aplication = this.getServletContext();
304-利用Servlet处理登录请求
在Servlet中使用application:
ServletContext application=this.getServletContext();
使用session:
request.getSession()
ServletContext application = this.getServletContext();//servlet中创建application。
获取session:
request.getSession();
1.获取application,因为不是传递参数过来的,需要使用this.getServletContext()方法来获取
返回值类型为ServletContext
ServletContext application = this.getServletContext();
2.获取session,因为跟客户端有关,每个客户端都不一样,所以使用传递过来的request的getSession()方法来获取session
返回值类型为HttpSession
HttpSession session = request.getSession();
Servlet中的application通过this.getServletContext()获取。this表示当前Servlet,application表示整个web应用,就是Servlet的context。
而session是客户端独立的,也就是跟请求相关,通过request.getSession()取得当前客户端的session。