473,397 Members | 2,033 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,397 software developers and data experts.

How to send Javascript variable to jsp page using AJAX?

I have tried sending the value as shown(code), but no value is being caught in JSP.

It is showing null value in jsp page.

this is javascript/ajax code

Expand|Select|Wrap|Line Numbers
  1. var emp = document.getElementById("Employee").value;
  2. var url_temp = "print_emp.jsp?Employee="+emp;
  3. alert(url_temp);
  4.  
  5.  
  6. var xmlhttp;
  7. if (window.XMLHttpRequest)
  8. {
  9.     // code for IE7+, Firefox, Chrome, Opera, Safari
  10.     xmlhttp=new XMLHttpRequest();
  11. }
  12. else
  13. {// code for IE6, IE5
  14.     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  15. }
  16. xmlhttp.onreadystatechange=function()
  17.     {
  18.  
  19.     if (xmlhttp.readyState==4 && xmlhttp.status==200)
  20. {
  21.         document.getElementById("result_display").innerHTML=xmlhttp.responseText;         
  22.           //document.getElementById(result_display).innerHTML="print_emp.jsp";
  23. }
  24. }
  25. xmlhttp.open("GET",url_temp,true);
  26. xmlhttp.send();
  27.  
  28.  
  29. trying to read in jsp page as shown below, but no use.
  30.  
  31. String employee=request.getParameter("emp");
  32. System.out.println("this is employee value"+employee);
Jan 22 '15 #1
1 4710
rajujrk
107 100+
Hi,

Please follow the rules, provide your code in CODE tag.

And Please ask questions clearly, from which JSP u r callind this javascript method and how do u want to navigate to print_emp.jsp?

Try to use hidden field

Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type="hidden" name="emp" id="emp">
  3.  
  4.  
In Javascript Code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. document.getElementById("emp").value = document.getElementById("Employee").value;
  3.  
  4. redirect/navigate to JSP
  5.  
  6.  
Jan 22 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
3
by: mudgilgaurav | last post by:
I am very keen to learn AJAX and want to use it in my website Can anyone give me a bunch of code abt ajax and as well as tell me the flow of code
1
nirmalsingh
by: nirmalsingh | last post by:
i am using ajax+c#+Mysql. with a table,textbox and save button. everything was inserted in database and loaded in table but the problem at rare timings i have to refresh html page to view saved...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
2
by: mrranjeetmca | last post by:
I would like to replace image retriving from database on click button using ajax. can any one help me to do that?...
5
vijcbe
by: vijcbe | last post by:
Hello friends!! My program goes like this.. I have a page where user id and password are entered. When they click submit button(input type is not submit), it goes to Javascript and sends AJAX...
2
by: soms2m | last post by:
hello all, I am a just a beginer in this community also to this topic, i want to load a page using ajax. the parent should not be refreshed also its should have a dim background color which one i...
0
by: Abubakar | last post by:
Hi, I've been assigned to work on a asp.net page that when viewed on internet, renders very slowly and its hosted on a client machine which is a p4 3.0ghz HT, with 2 gb ram running windows...
1
by: ashwani40 | last post by:
I am having a site in which dynamically header part is changing as in each and every page there is a script called which checks the referring url and according to that url script invoke a header.html...
2
by: riskmonster | last post by:
There is a Jsp page. the page have four div list data. and every div is a link . so ,what should i do click this link to refresh this div using Ajax?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.