浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

metro2.0下载地址:

https://metro.dev.java.net/2.0/metro-2_0.zip

metro-eclipse plugin下载地址:

https://metroplugineclipse.dev.java.net/files/documents/9069/146014/metroplugins.zip

原文:

http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html

 

 

@WebService
public class Hello {
    @Resource
    private WebServiceContext wsContext;
    public int getCounter(){
        MessageContext mc = wsContext.getMessageContext();
        HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
        // Get a session property "counter" from context
        if (session == null)
            throw new WebServiceException("No session in WebServiceContext");
        Integer counter = (Integer)session.getAttribute("counter");
        if (counter == null) {
            counter = new Integer(0);
            System.out.println("Starting the Session");
        }
        counter = new Integer(counter.intValue() + 1);
        session.setAttribute("counter", counter);
        return counter;

    }
}

posted on 2010-01-09 00:50  浙林龙哥  阅读(302)  评论(0编辑  收藏  举报