V
V
Viktoria Smirnova2017-08-15 11:16:28
Java
Viktoria Smirnova, 2017-08-15 11:16:28

Error when displaying "Hello World!"?

I'm struggling and can't cope with the simplest, the "printText" method in the Class class, in request.setAttributea JSP servlet, displays an error 500, look at the code, what's wrong? Tomcat8, IntelliJ IDEA Ultimate

Class, Servlet:

public class Servlet extends HttpServlet {

public class PrintText {
    public String printText() {
              return "Hello!";
    }

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

         PrintText p = new PrintText();
         p.printText();
         request.setAttribute("p", p); 
         request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
    }
    }


jsp:

<html>
<body>
<p>${p.printText}</p> 
</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-08-15
@Vika7

Replace the name of the printText method with getText, and the EL expression with ${p.text}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question