Ajax, JSP and Servlets

1

I have problems executing an application on the server that greets when entering the name, my files are      index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Demo Ajax</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('#bttHello').click(function(){
     var fullname = $('#fullname').val();
     $.ajax({
         type:'POST',
         data: {fullname:fullname},
         url:'AjaxController',
         success: function(result){
             $('#result1').html(result);
            }

        });
    }); 
 });
</script>
</head>

<body>
 <form>
   Name <input type="text" id="fullname"><input type="button" 
    value="Hello" id="bttHello">
    <br>
    <span id="result1"></span>
 </form>
</body>
</html>

and AjaxController.java

package controladores;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class AjaxController
 */
@WebServlet("/AjaxController")
public class AjaxController extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public AjaxController() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse        response) throws ServletException, IOException {

}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse    response) throws ServletException, IOException {
    response.setContentType("text/plain ");
    String fullname = request.getParameter("fullname");
    PrintWriter out =  response.getWriter();
    out.print("Hello" + fullname);
}

}

I would like to be able to print the message in this way but I run the program and it does not print the message, the example should have been like this:

who think it was wrong, I followed the tutorial to the letter but I can not print the message.

    
asked by Gerardo Bautista 20.05.2017 в 00:18
source

0 answers