Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

jax ws - How can we use servlet to consume a web service?

I am using eclipse 2019-12R, Apache 9.0 and jdk1.8

I am working with Soap Web Service. I have a project name WebApplication1 which has a WebService NewWebService.wsdl of adding 2 numbers. I am able to generate a wsdl file also. I want to use this web service in another project WebApplication2. I want to use servlet in WebApplication2 to access a web service which is in WebApplication1 i,e NewWebService.wsdl. I want input from html file and display the result in the browser.

I am not sure whether i am coding right way or not. Any help would be much appreciated.

public class NewServlet extends HttpServlet {
    
    @WebServiceRef(wsdlLocation = "http://localhost:8080/WebApplication1/services/NewWebService?wsdl")

    public com.abc.def6.NewWebServiceService service;
    
    
    
    @Override
     public void doPost (HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
     {
         res.setContentType("text/html");
         PrintWriter pw=res.getWriter();
         int c=Integer.parseInt(req.getParameter("a"));
         int d=Integer.parseInt(req.getParameter("b"));
         
         NewWebService port = service.getPort("NewWebService");//Dont know whether this is right way or not.
         int result = port.add(c,d);

         if(req.getParameter("btn1")!=null){
             pw.print("<h1>"+result+"</h1>");
             
         }
         
     }

}```
question from:https://stackoverflow.com/questions/65952398/how-can-we-use-servlet-to-consume-a-web-service

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...