【转载】servlet中创建与获取session
来源:互联网 发布:农村淘宝服务站佣金 编辑:程序博客网 时间:2024/06/10 08:43
1.原理图(简图)
2.代码
设置session
imp
imp
imp
public class setSession extends HttpServlet{
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException{
HttpSession session=req.getSession();//返回与当前request相关联的session,如果没有则在服务器端创建一个;
session.setAttribute("username","zhangjie");
resp.getWriter().println("------setSession() is ok--------");
}
}
获取session:
imp
imp
imp
public class getSession extends HttpServlet{
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException{
HttpSession session=req.getSession();//返回与当前request相关联的session,如果没有则在服务器端创建一个;
resp.getWriter().println(session.getAttribute("username"));
resp.getWriter().println("------getSession() is ok--------");
}
}
- 【转载】servlet中创建与获取session
- Struts2中与Servlet API进行耦合获取servlet中的application,session,request对象
- 在servlet中创建和应用session
- Servlet创建Session
- Servlet--Session创建时间
- Servlet--获取Session对象
- Servlet 中 session 的创建、销毁及监听
- Jsp页面获取不到Servlet中session保存的值
- Servlet-Session与Cookies
- Servlet与Session
- Servlet-Cookie 与 Session
- Servlet Session 与 Cookie
- servlet中使用session
- servlet中使用session
- servlet中使用session
- servlet中使用session
- [转载]JAVA类中通过Servlet操作JSP中Session变量方法
- Hibernate中SessionFactory的创建和Session的获取
- loading win32com: java.lang.UnsatisfiedLinkError: no win32com in java.library.path
- java事件机制之通过上下左右键来控制小球为位置的移动演示
- 把request对象中的请求参数封装到bean中的工具类
- dom4j操作XML
- 解决在angular 中swiper 不能滑动问题
- 【转载】servlet中创建与获取session
- android复习路之不死的service
- 【转载】EL表达式取Map值需要注意的
- java基础加强
- 【转载】9幅图,9句话,总有一句让你豁然开朗
- Python 调试工具 PDB(Linux 环境下调试)
- Spring学习笔记(一)-控制反转
- Spring学习笔记(二)-@Resource注解的使用规则
- xshell连接本机vmware上的linux