When returning the hashmap to javascript I get the following error:
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
Calling the javascript validames () function:
<div data-role="controlgroup">
<label for="txtMesa">Informe a mesa de origem:</label>
<input type="text" name="codigo" id="txtMesa" maxlength="3" onchange="validamesa()"/>
</div>
Validate function in js file:
function validamesa(){
var mesa = document.getElementById("txtMesa").value;
if (mesa != null || mesa != "")
{
$.ajax( {
type : "GET",
url : "validarMesa.do?mesa="+mesa,
success : function(data) {
if (data.mensagem != "OK"){
alert(data.mensagem);
document.getElementById("txtMesa").value = "";
document.getElementById("txtMesa").focus();
}
}
error : function(msg) {
console.log(msg.responseText);
alert("Erro:"+msg.responseText);
}
});
}
}
Now the Spring MVC @RequestMapping:
@RequestMapping("/validarMesa.do")
public @ResponseBody
Map<String, ? extends Object> validarMesa(BigDecimal mesa,
HttpSession session, HttpServletRequest req,
HttpServletResponse resp) {
Map<String, Object> modelMap = null;
Tab_MesasDao oMesaDao = null;
try {
oMesaDao = new Tab_MesasDao();
if (oMesaDao.validar_Mesa(mesa)) {
modelMap = new HashMap<String, Object>(1);
modelMap.put("mensagem", "OK");
resp.setStatus(200);
} else {
modelMap = new HashMap<String, Object>(1);
modelMap.put("mensagem", "ERRO!" + oMesaDao.getMensagem());
resp.setStatus(200);
}
} catch (Exception ex) {
modelMap = new HashMap<String, Object>(1);
modelMap.put("mensagem", "ERRO!" + ex.getMessage());
resp.setStatus(404);
} finally {
oMesaDao = null;
}
return modelMap;
}
I've been having this problem for a few days already and I have not found any forums to help me. Has anyone had this problem? I'm starting now with JavaWeb.