I'm trying to retrieve the value in JSP which has been submitted via XHR request in HTML
Below is the HTML code for reference
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js">
</script>
<script>
function click() {
var xhr = null;
if (navigator.appName == 'Microsoft Internet Explorer') {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else if (navigator.appName == 'Netscape') {
xhr = new XMLHttpRequest();
}
xhr.open('POST', "verify.jsp", true);
var params = 'empIds=' + '123';
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
alert(xhr.responseText);
}
};
xhr.send(params);
}
</script>
</head>
<body>
<p><button onclick="click()" type="button">Click</button></p>
Below is the JSP Page which retrieves the value submitted
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<BR>
<%
long timeInMilliSeconds = System.currentTimeMillis();
String empId = request.getParameter("empIds");
out.print("emp Id: "+empId);
%>
</BODY>
</HTML>
Actual Result: empId:
Expected Result:empId: 123
JSP should retrieve the value and send the same value back to HTML
Reason: String empId = request.getParameter("empIds"); is returning null.
Thanks