gpt4 book ai didi

java - 我们可以在 webservice 方法中调用 servlet

转载 作者:行者123 更新时间:2023-12-01 19:19:11 24 4
gpt4 key购买 nike

我有一个网络服务方法

  @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 类吗?

最佳答案

为了调用该类,您必须创建它的实例,自己构造 HttpServletRequest 对象,然后调用它。或者您可以从 Web 服务向其发出 Http 请求。

不推荐这两种解决方案。您最好创建一个类来实现所需的功能并从两个地方调用它。

关于java - 我们可以在 webservice 方法中调用 servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5190904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com