I am facing an issue while trying to pass a JSON object from a JavaScript file to a servlet. I am getting a null value when trying to retrieve the data in the servlet. Please suggest how to resolve this problem as I am unable to extract data from the JSON object.
JSON Object:
var Record ={
Username:document.getElementById("username").value,
Name:document.getElementById("name").value,
Contact:document.getElementById("phone").value,
Email:document.getElementById("Email").value,
DOB:document.getElementById("date").value,
Team:team,
Position:Position,
PermanentAddress:document.getElementById("per_add").value,
PermanentCountry:document.getElementById("country").value,
permanentState:document.getElementById("state").value,
permanentCity:document.getElementById("city").value,
CurrentAddress:document.getElementById("CurrentAddress").value,
CurrentCountry:document.getElementById("currentCountry").value,
CurrentState:document.getElementById("currentState").value,
CurrentCity:document.getElementById("currentCity").value
}
Data being sent:
var PlayerData = JSON.stringify(Record);
$.post('/FootballLeagueController', PlayerData)
In servlet:
Gson gson=new Gson();
FootballPlayerData playerData=new Gson().fromJson(request.getParameter("PlayerData")
,FootballPlayerData.class); //(comment)Note :-FootballPlayerData is my pojo class.