Results 1 to 2 of 2
  1. #1
    rapiddata is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default make a URL Get call to an external web site from a jsp scriplet

    Hi
    From the jsp scriplet, I want to make a URL Get call to an external web site.

    How can I do this?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    the apache commons-httpclient project is a HTTP client.

    Java Code:
    <%
    String url = "your.url";
    HttpClient hclient = new HttpClient();
    GetMethod method = new GetMethod(url);
    int responseCode = hclient.executeMethod(method);
    String responseBody = "";    
    switch (responseCode) {
        case HttpStatus.SC_OK:
           responseBody = method.getResponseBodyAsString();
           break;
         default:
            break;
        }
    method.releaseConnection();
    %>
    
    <%=responseBody%>
    I guess the JSP purists would say this should be put into a JSP tag
    where the JSP would have <my:invokeUrl url=""/>

Similar Threads

  1. how do i make java external/internal?
    By zoon81 in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 10:59 AM
  2. [SOLVED] JSTL equiv of this scriplet?
    By playwin2 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-13-2009, 11:18 AM
  3. problem with scriplet code in jsp
    By rakesh_n_mehta in forum Advanced Java
    Replies: 1
    Last Post: 02-10-2009, 02:03 PM
  4. scriplet in javascript function in jsp page
    By Renjini in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-21-2008, 02:07 PM
  5. Is it possible to make a Phone call program using java?
    By fireball2008 in forum New To Java
    Replies: 2
    Last Post: 05-08-2008, 07:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •