Can't connect to the test servlet, what am I doing wrong?

Why the pattern does not work and then redirect?

Form Code:

<form action="Hello" method="post" onsubmit="return checkForm(this);"> <input type="submit" value="Добавить запись"> </form> 

Servlet code:

 @WebServlet(name = "Hello", urlPatterns = {"/Hello"}) public class Hello extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.sendRedirect("/Testcracker/pages/search.jsp"); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } } 
  • action must not Hello, but / app / Hello where app is the name of your web application - Russtam

1 answer 1

Problem solved. Based on it, wrote controllers for the application. The problem was in the absence of the response.setContentType line ("text / html; charset = UTF-8") ;. By adding it to the servlet, I received both redirects and more complex solutions. About the comment about action. I registered url pattern / pages / Hello in xml, and left everything in the form as it is. If you suddenly need a code, then unsubscribe.