Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple fetch

Posted on 2002-05-31
13
Medium Priority
?
190 Views
Last Modified: 2010-03-31
My friend wrote a jsp script for me and I want to add a small function inside it.

Using <%=url%> variable I need to fetch the contents of that url and to print them to screen.

Can someone help me out?
0
Comment
Question by:eugeneg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047606
why not simply do:

<jsp:include page="<url>" flush="true" />
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047614
sorry, forgot to mention that this will only work if url is a resource in your current servlet context.
0
 

Author Comment

by:eugeneg
ID: 7047620
how about if its not on my server?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Accepted Solution

by:
bobbit31 earned 800 total points
ID: 7047623
you can try this as well:
<%@ page import="java.net.URL,
                     java.net.URLConnection,
                     java.io.*" %>
<%
BufferedReader in = null;

try {
     URL myURL = new URL ("http://java.sun.com");
     URLConnection con = myURL.openConnection();

     in     = new BufferedReader(new InputStreamReader(con.getInputStream()));

     String s;
     
     // read in result
    while ((s = in.readLine()) != null) {
          out.println(s);
    }
} finally {
     // close stream
     try {
          if (in != null) {     in.close(); }
     } catch (IOException ie) {}
}
%>
0
 

Author Comment

by:eugeneg
ID: 7047634
One more thing, i'll need to pass some variables as parameters, something like:
    URL myURL = new URL ("http://java.sun.com?id=ID");

i want to use the id variables that is used though out the whole jsp.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047640
i'm not sure i understand you correctly but if you have a variable ID used in your jsp, you can do something like:

URL myURL = new URL ("http://java.sun.com?id=" + ID);

0
 

Author Comment

by:eugeneg
ID: 7047654
I'm passing 2 variables and ran into problem:
    URL myURL = new URL ("http://www.script.cgi?id="+id"&pass="+pass);
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047656
URL myURL = new URL ("http://www.script.cgi?id=" + id + "&pass=" + pass);
0
 

Author Comment

by:eugeneg
ID: 7047676
the code works but the variables arent getting passed. i wonder why.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047688
id and pass variables must be set before calling new URL(...)

can you post your code?
0
 

Author Comment

by:eugeneg
ID: 7047693
i see id and pass are set becuase when i do:

         out.println(id);
I get the id.

But for some reason this doesnt work:
URL myURL = new URL ("http://www.script.cgi?id=" + id + "&pass=" + pass);

still trying to figure it out.
0
 

Author Comment

by:eugeneg
ID: 7047703
Great answers and helped me figure out my problems until everything worked on my site.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 7047706
glad you got it working!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question