473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

return value from JSP to Javascript

Hello all,

I would like to call a JSP from a Javascript and get a result on my
javascript

To call the JSP I'm doing like that :

<SCRIPT LANGUAGE="Javascript1.1">
function test()
{
var img = new Image();
img.src= 'http://myserver/jsp/test/test2.jsp';
}

It works fine, but I don't know how I could get a return value from
the JSP to the Javascript

Thanks for any help

Denis
Jul 20 '05 #1
2 25844
In article <5b**************************@posting.google.com >,
ds******@ptc.com (dsimonneau) wrote:
Hello all,

I would like to call a JSP from a Javascript and get a result on my
javascript

To call the JSP I'm doing like that :

<SCRIPT LANGUAGE="Javascript1.1">
function test()
{
var img = new Image();
img.src= 'http://myserver/jsp/test/test2.jsp';
}

It works fine, but I don't know how I could get a return value from
the JSP to the Javascript


One option: load JSP into an invisible frame.
Warning: the idea is simple but things get complicated fast.

Here's a short 3 file demo. Note the use of onload
to tell main.html when the data has been sent.

File 1: demo.html -- sets up the empty frame

<html><head><title>JSP Javascript Demo</title></head>
<frameset cols="0%, *">
<frame name="data" frameborder="0">
<frame name="main" src="main.html" frameborder="0">
</frameset>
</body>
</html>

File 2: main.html -- defines one function to ask for data,
another to respond when it's ready

<html><head><title>Main Page</title>
<script language="javascript">
function getData() { top.data.location.reload("data.jsp"); }

function dataLoaded() { alert("It is now " + top.data.date); }
</script>
</head>
<body>
<form>
<input type="button" value="For a good time..." onclick="getData()">
</form>
</body>
</html>

File 3: data.jsp -- uses JSP to set Javascript variables

<html><head>Data page</title>
<script language="javascript">
var date = "<%= new java.util.Date() %>";
</script>
</head>
<body onload="top.main.dataLoaded()">
<p>Move along, nothing to see here.</p></body>
</html>
Jul 20 '05 #2
ds******@ptc.com (dsimonneau) wrote in message news:<5b**************************@posting.google. com>...
I would like to call a JSP from a Javascript and get a result on my
javascript


Here is an old example of dynamically creating <SCRIPT> elements. In
this example, it uses a text file (alert.txt) as the source of the
script, but you can replace the value with a JSP.

// ---- start of code
// ---- loader.htm

<html>
<head>
<script type="text/javascript">
var newScript;
function init ( ) {
createScript ( );
}
function createScript ( ) {
newScript = document.createElement ( "SCRIPT" );
newScript.src = "alert.txt";
document.body.appendChild ( newScript );
}
function destroyScript ( ) {
if ( newScript != null ) {
document.body.removeChild ( newScript );
}
newScript = null;
}
</script>
</head>
<body onload="init()">
</body>
</html>

// ---- alert.txt

alert ( "this is from a text file" );

// ---- end of code

All you have to make sure of is that the URL used to supply the src
MUST return executable JavaScript. It really does not matter what the
URL is (JSP, ASP, text, etc.) as long as its JS.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: PvdK | last post by:
Hello, I have a form in which the user can enter a query in a query language. The form is submitted to a perl script that checks if the syntax is OK and if yes, execute the query and generates...
7
by: sindre | last post by:
Hi, Some place I use links to submit forms instead of a submit button. The way I have done this is: <a href="javascript:document.getElementById('<?php print "delete$i"...
1
by: ms_chika | last post by:
Please help! I just want to know how can i pass the return value of a javascript function to a xsl variable. I have an xsl file and from that file i will call a javascript function then the...
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
9
by: Water Cooler v2 | last post by:
Is it necessary to return a value from the event handlers? For instance, what does the return value in the following code signify? What will be its impact if it returned otherwise (true)? <a...
2
by: info | last post by:
Hi... I want to know (inside a function) if the calling code wants a return value or not. Here is an example: function foo() {
1
by: mailpitches | last post by:
X-No-Archive: yes a function, the return value of the function is a boolean. What does this boolean value mean? Example: <body onload="document.getElementById('field').onkeydown=function(x) {...
6
by: =?Utf-8?B?Um9i?= | last post by:
Hi, If I call my own DLL from Javascript, a HRESULT is returned. Javascript cannot cast this to an integer. Is there any other way of typecasting this returnvalue to integer, wihout using the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.