Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

use the response to return a value to javascript

Posted on 2003-03-19
9
Medium Priority
?
149 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
If you need to complete a Physical to Virtual (P2V), Virtual to Virtual (V2V) conversion to a VMware product (VMware Workstation, Player or VMware vSphere (ESXi) ) for FREE, then there is some good news...
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

572 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