×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
Hello guys,

I need to call an webservice that is in an address like this: http://www.address.com/service.cfm

I used to use it in a jsp, in a form, doing something like: <form action="http://www.address.com/service.cfm"> ...

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

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

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
http://www.primrose.org.uk

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

(OP)
Sorry, bad explanation. I just need to do the same in a servlet.

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

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
http://www.primrose.org.uk

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

(OP)
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

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

Quote:


 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
http://www.primrose.org.uk

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

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);
    }
  }
}

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close