?
Solved

use the response to return a value to javascript

Posted on 2003-03-19
9
Medium Priority
?
148 Views
Last Modified: 2010-04-01
I call a JSP page from my Javscript function..
var jspvalue = process.jsp?cmd=1;

and in the JSP page

<% string cmdval = request.getParameter(cmd)....
...
if (cmd.equals("1") {
......
 String returnvalue = "xyz";
,...
}

PrintWriter out = response.getWriter();
out.write(returnvalue);
out.flush();

Obviously this does not work. Is there anyway i can do this?..
The Javscript and the JSP needs to be separate for various reasons in the application.
Any help appreciated ..
Thanks
0
Comment
Question by:gayuk
[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
  • 5
  • 3
9 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8170460
what do you want to achieve? javascript is client (browser) side language, and jsp is server side language.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8170466
i.e. the jsp won't be executed unless you send a new request to server.
0
 

Expert Comment

by:avexus
ID: 8170490
You can use Javascript to submit a URL referencing the jsp:

http://<serer>:<port>/process.jsp?cmd=1

Then in your JSP you can set the return value into the response as you were doing.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gayuk
ID: 8170496
i am sending the request..
I can get this to work:

Say i want to change the image src :

i can do:
document.img.src = process.jsp


and in process.jsp i can do a response.getOutputStream() and change the image..

Is it possible to do the same thing for a variable?
0
 

Author Comment

by:gayuk
ID: 8170513
avexus:

The problem is it does not seem to change the variable value

( i also tested it by sending back the url to an image and it does not seem to send it back)..
I was wondering if i should send change the response in some way..
0
 

Author Comment

by:gayuk
ID: 8170535
avexus:

The problem is it does not seem to change the variable value

( i also tested it by sending back the url to an image and it does not seem to send it back)..
I was wondering if i should send change the response in some way..
0
 

Author Comment

by:gayuk
ID: 8170571
avexus:

The problem is it does not seem to change the variable value

( i also tested it by sending back the url to an image and it does not seem to send it back)..
I was wondering if i should send change the response in some way..
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 75 total points
ID: 8170943
>> i can do:
>> document.img.src = process.jsp
Yes

>>Is it possible to do the same thing for a variable?
No!

but you can achive this goal by using hidden frame:
http://insights.iwarp.com/advanced/hiddenframe.html
0
 

Author Comment

by:gayuk
ID: 8221142
Thanks
I have since realized that when you do a .src sends a request to the page because it is a url..
However, with a variable, it does not submit to the page which is why you want to submit a form
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Introducing Priority Question, our latest feature.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

764 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