Я совершенно новичок в AJAX, поэтому этот вопрос. Я хочу отправить некоторую информацию из моего кода JavaScript в мой сервлет.
function getDetails() {
vals = document.getElementById("name").value;//works: vals does get inputted value
request = createRequest();
if (request == null) {
alert("Unable to create request");
return;
}
var url= "ValidateUser.do";
request.open("POST", url, true);
request.onreadystatechange = displayDetails;
//How do I send the value of "vals" to my servlet?
request.send("name="+vals);
}
Когда я запускаю req.getParameter ("name") на своем сервлете, я всегда не получаю значения, даже если "vals" действительно содержит введенное значение. Поэтому мой вопрос - как мне получить доступ к этому значению из моего сервлета?
EDIT:
function createRequest() {
try {
request = new XMLHttpRequest();
} catch (tryMS) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (otherMS) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
return request;
}
ДОПОЛНИТЕЛЬНОЕ РЕДАКТИРОВАНИЕ:
Код сервлета: я хочу, чтобы оператор println выводил имя.
//shortened: this method is called by a ControllerServlet
public Object perform(HttpServletRequest req, HttpServletResponse resp) {
//retrieve customer from database
model = SeekerCustomer.getCustomer(req.getParameter("name"));
System.out.println(req.getParameter("name"));
}