// ServletContextListener Class
public void contextInitialized(ServletContextEvent sce) {
try {
sce.getServletContext().setAttribute("myBook", "Learning java");
} catch (Exception ex) {
}
}
// WebService
@Resource
WebServiceContext wsContext;
@WebMethod(operationName = "test1")
public String test1() {
ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
String myBook = (String) servletContext.getAttribute("myBook");
}
沒有留言:
張貼留言