运行servlet我只得到一个Hello World

时间:2020-01-20 10:58:46

标签: java tomcat servlets netbeans glassfish

当我运行项目时,即使我犯了很多错误(例如将方法doGet()的名称更改为domGet),它也始终使用“ Hello World!”打开浏览器。我不知道为什么它会继续这样做,我停止了Tomcat服务器,但仍然得到Hello World标志。希望您能为我提供帮助,我花了数小时寻找解决方案。这是代码

package alumni;

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;

public class ServletPersonaa extends HttpServlet {
        private static final long serialVersionUID = 1L;


    public ServletPersonaa()   {
    super();
    }

    @Override
   protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();

        // Envia información
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Datos de la Persona </title>");
        out.println("</head>");
        out.println("<body>");

        out.println("El nombre es: " + request.getParameter("nombre"));
        out.println("<BR>");
        out.println("El apellido es: " + request.getParameter("apellido"));
        out.println("<BR>");
        out.println("El domicilio es: " + request.getParameter("domicilio"));
        out.println("<BR>");
        out.println("El pais es: " + request.getParameter("pais"));
        out.println("<BR>");
        out.println("</body>");
        out.println("</html>");
        out.close();
   }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }

    }

0 个答案:

没有答案