裏面我有一個Web服務方法我們可以調用一個servlet web服務方法
@WebMethod
public void getCapturedImages(String image)
System.out.println(" image " + image);
}
而且我的servlet類:
public class GetWebApplicationPathServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static ServletContext context;
public static ServletContext getContext() {
return context;
}
public static void setContext(ServletContext context) {
GetWebApplicationPathServlet.context = context;
}
/**
* @see HttpServlet#HttpServlet()
*/
public GetWebApplicationPathServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("doGet(HttpServletRequest");
String path = getServletContext().getRealPath("");
context = getServletContext();
String path1 = context.getRealPath("/images");
System.out.println("path1"+path1);
/*
* PrintWriter writer = response.getWriter();
* writer.println("Application path: " + path);
*/
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
,我們可以調用webservice的方法在我的servlet類。
我的情況下返回空值..給出一個解決方案請 – jennifer 2011-03-04 09:15:49
我使用帶有JboSS工具包的eclipse創建了webservices。另外通過使用WebServiceContext註釋,上下文值爲null .. – jennifer 2011-03-04 09:24:34
@jennifer根據http://stackoverflow.com/questions/261348/how-can-i-access-the-servletcontext-from-within-a中的評論-jax-ws-web-service/261349#261349您應該嘗試刪除WEB-INF/lib中的common-annotations.jar,因爲這會導致類加載器衝突。目前無法進一步調查。 – 2011-03-04 11:11:40