I am trying to get array, which is created in javascript function to my java class.
In my java class this array comes as a null value.
here is my jsp code,
<input type="button" value="Submit" onClick="submit()" />
<script>
var a = "I am A"
var b = "I am B"
var c = "I am C"
var arr = [a,b,c];
function submit() {
$.ajax({
method : "POST",
url : 'myServlet',
dataType : "text/html",
data : {sts:arr}
success : function(resp) {
},
error : function(data) {
},
});
}
</script>
<!-- </form> -->
</body>
</html>
my java class to access the array,
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
String[] n=request.getParameterValues("sts");
System.out.println(n);
}
also tried the following
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
String[] n=request.getParameterValues("sts[]");
System.out.println(n);
}
both prints only null and not array.
Can anyone say where the mistake happens?
Thanks in advance.