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;
}
}