Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a webservice (cfm) from a servlet?

Status
Not open for further replies.

SuperMoonster

Programmer
Aug 11, 2005
59
BR
Hello guys,

I need to call an webservice that is in an address like this:
I used to use it in a jsp, in a form, doing something like: <form action=" ...

The problem is that now I cannot use a jsp. I want to call it from the servlet (sending and receiving the parameters).. without any jsp.

Can someone show me how?

thanks
 
Is it a webservice as in a SOAP web service ? You cannot post to a webservice in this sense using a <form> html tag.

Has it changed to an actual webservice, or do you just need to do the same in a servlet ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ahh.. in that case, you can either :

If its a GET HTTP request, then just get a RequestDispatcher object from the response object, and use a sendRedirect() (sp?).

Or, use the HttpUrlConnection and send your data to that URL (which would support a POST or GET request).

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
But this cfm site receives data that I used to send to it in my jsp through parameters, and it also returns data through parameters.

The return is easy, I just do a request.getParameter("aa"), I suppose. But how do I set and send this request parameters on my servlet?

thanks for the attention
 
and it also returns data through parameter

Not sure what you mean by this exactly.
I would have a look at HttpUrlConnection object - this can send and receive HTTP based data - its just a bit more loe level that 'normal JSP' ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Code:
// if you use tomcat, write a simple jsp and run that jsp, then you can find the generated code in the work directory

<jsp:forward page="for2.jsp">
<jsp:param name="YourName" value="Tom" />
</jsp:forward>

The generated code look like this

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class for1_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      if (true) {
        pageContext.forward("for2.jsp" + (("for2.jsp").indexOf('?')>0? '&': '?') + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("YourName", request.getCharacterEncoding())+ "=" + org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode("Tom", request.getCharacterEncoding()));
        return;
      }
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (pageContext != null) pageContext.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
    }
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top