Output of a servlet inside another page

I like to include the result of a servlets output on a diffrent server inside an static html page. is this possible? I know that you can do this with cgi but how is it done with a servlet
[201 byte] By [ajalali] at [2007-9-26 3:55:03]
# 1

hi

one solution: make .jsp file and include output of a servlet in different server by making

<%

String line = "";

try {

URL url = new URL(

"http://127.0.0.1/servlets/test?name=Test");

BufferedReader in = new BufferedReader(

new InputStreamReader(url.openStream()));

line = in.readLine();

out.println( line );

in.close();

}catch (Exception e){

e.printStackTrace();

}

}

%>

<!-- here goes ur rest html code -->

psvinayram at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
The problem is that on the server that I want the servlet output, it doesn't suport jsp or anything else. it's a static page. so far the only way that it works is if i use frames.
ajalali at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
a
ajalali at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

The scheme presented by psvinayram above doesnot have to be in a JSP.

You could run the same code from a Java application.

Or is it that you want the output from a servlet to be presented inside an otherwise existing HTML page without any coding ? That would be interesting indeed !

neville_sequeira at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

yes the output of the servlet would go inside another html page on a remote server that does not suport java or anything. the only thing that I could think of so far was to link it in this way

<script src="http://server1.com/servlet/TestServet">

but I think that doesn't work I have play with that to see

ajalali at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Ok actualy this is what you do.

first you create a servlet but the output needs to be a javascript code

for example:

PrintWriter out = res.getWriter();

out.println( "function getOutput(){" );

out.println( "document.write('bla bla bla');" );

out.println( "}" );

out.close();

then you link a javascript file to this servlet. so the html would look like this:

<html>

<head>

<script src="url of the servlet"></script>

</head>

<body>

<script>

// a call to the java script function that your servlet outputs.

getOutput();

</script>

</body>

</html>

the result is that bla bla is printed in this page

ajalali at 2007-6-29 12:44:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...