Я настоятельно рекомендую проверить ответ BalusC здесь на вопрос о том, как сделать ajax с сервлетами.
Я заметил, что вы используете jquery, вы также можете создать свой запрос ajax следующим образом:
<script>
$(document).on("click", "#submit", function() {
var value = $('#val').val(); //get value you want to send
var params = {value : value}; //set it as one of the parameters
$.post("FormList", $.param(params), function(response) { //make ajax request
$('#res').text(response); //retrieve response and set it to #res
});
});
</script>
Но в любом случае, причина, по которой вы видите только html, заключается в том, что вы ничего не пишетевернуться к ответу.Вам нужно сделать это так:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String value = request.getParameter("value");
response.setContentType("text/plain"); // Set content type of the response so that jQuery knows what it can expect.
response.setCharacterEncoding("UTF-8"); // You want world domination, huh?
response.getWriter().write(value); // Write response body. (not print)
}