开发者

Manually implementing client side session

I have a simple servlet which is adding a session v开发者_开发百科ariable. To request the session variable I can just from within another servlet I can use -

request.getSession().getAttribute

But how can I request this variable on client side that does not implement the servlet spec. In this case im using MIDP.

public class SetTestStartTime extends HttpServlet{

        public void doGet(HttpServletRequest request, HttpServletResponse response) {

            Long currentTimeMilliSeconds = System.currentTimeMillis();
            request.getSession().setAttribute("time", currentTimeMilliSeconds);


        }

}


you cannot read session variable in client side. but you can write your session data to http header and you can read them from j2me applicaiton.

in servlet

public class SetTestStartTime extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    Long currentTimeMilliSeconds = System.currentTimeMillis();
    request.getSession().setAttribute("time", currentTimeMilliSeconds);
    response.addHeader("time", request.getSession().getAttribute("time"));
}
}

and in j2me

HttpConnection con = ....;
String time = con.getHeaderField("time");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜