URL重写实现会话跟踪
来源:互联网 发布:淘宝充流量如何退款 编辑:程序博客网 时间:2024/05/16 17:33
为了说明URL Rewriting技术,我们编写sevlet实现访问记数。下面代码显示了CounterRewriteServlet的源程序,它使用URL Rewriting技术来在HTTP请求之间维护会话信息。
package sample;
import javax.servlet.*;
import javax.servlet.http.*;
public class CounterRewrite extends HttpServlet
{
static final String COUNTER_KEY = "CounterRewrite.count";
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, java.io.IOException
{
resp.setContentType("text/html");
java.io.PrintWriter out = resp.getWriter();
HttpSession session = req.getSession(true);
int count = 1;
Integer i = (Integer) session.getValue(COUNTER_KEY);
if (i != null) {
count = i.intValue() + 1;
}
session.putValue(COUNTER_KEY, new Integer(count));
out.println("<html>");
out.println("<head>");
out.println("<title>Session Counter " +"with URL rewriting</title>");
out.println("</head>");
out.println("<body>");
out.println("Your session ID is <b>" +session.getId());
out.println("</b> and you have hit this page <b>" +count +
"</b> time(s) during this browser session");
String url = req.getRequestURI()+ ";" + SESSION_KEY +session.getId();
out.println("<form method=POST action=\"" +resp.encodeUrl(url) + "\">");
out.println("<input type=submit " +"value=\"Hit page again\">");
out.println("</form>");
out.println("</body>");
out.println("</html>");
out.flush();
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException
{
doGet(req, resp);
}
}
请注意,encodeURL方法被用来修改URL,使URL包含会话ID;encodeRedirectURL被用来重定向页面
- URL重写实现会话跟踪
- URL重写实现会话跟踪
- 使用 URL 重写跟踪会话
- jsp的URL重写实现会话跟踪技术
- 会话跟踪技术:会话Cookie,URL重写和HttpSession
- 会话跟踪技术:会话Cookie,URL重写和HttpSession
- 会话跟踪技术:会话Cookie,URL重写和HttpSession
- URL重写实现session跟踪
- URL 重写来实现会话管理
- 主题:URL 重写来实现会话管理
- 用URL重写来实现会话管理
- 使用url重写实现Session跟踪
- servlet url 重写实现session跟踪
- URL重写 实现会话管理 http状态保持
- 会话跟踪技术介绍——cookie ,url 重写, 隐藏表单域
- jsp页面中的session、cookies、隐藏域、url重写四种会话及跟踪方式
- jsp页面中的session、cookies、隐藏域、url重写四种会话及跟踪方式
- jsp页面中的session、cookies、隐藏域、url重写四种会话及跟踪方式
- 图像、帧、片、NALU(zz)
- 在Visual Assist X中增加Doxygen格式的注解的模板 [RT,修改]
- 联系人ProfileProvider
- windows的磁盘操作之三——获取和删除磁盘分区信息
- s3c2440的U-boot移植(一)
- URL重写实现会话跟踪
- windows的磁盘操作之四——根据逻辑分区号获得物理磁盘号
- 修改Visual Assist中的方法注释样式;Eclipse中使用doxygen注释C++方法
- Ubuntu 13.04 完全配置
- windows的磁盘操作之五——获取物理磁盘上的所有逻辑分区号
- Gallery的应用以及点击显示点击的是第几张图片
- windows的磁盘操作之六——获取系统所在物理磁盘号
- 为什么学C++比C#的长期风险低
- windows的磁盘操作之七——获取当前所有的物理磁盘号