'How to return the value to HTML from JSP
Root Issue: Unable to get the value in JSP sent by the HTML xhr request.
HTML
<!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>
JSP Page
<%@ 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
Please help me where i did the mistake or how to fix it. Basically want to send the value from HTML to JSP. JSP should retrieve the value and send the same value back to HTML
Reason: String empId = request.getParameter("empIds"); is returning null.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
