Vika7
@Vika7
вебист

Как вывести метод класса в JSP из сервлета?

Как будет верно указать в
request.setAttribute


public class Servlet extends HttpServlet {

public class PrintText {
    public void printText() throws Exception {
              System.out.println("Hello!");
    }
}

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

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


в JSP ${}:
<html>
<body>
<p>${-------}</p> 
</body>
</html>
  • Вопрос задан
  • 468 просмотров
Пригласить эксперта
Ответы на вопрос 1
drno-reg
@drno-reg
см не кратко
в сервлете

request.setAttribute("example1", p.printText());

в JSP
<p>${example1}</p>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
04 мая 2024, в 22:32
2000 руб./за проект
04 мая 2024, в 22:10
2001 руб./за проект
04 мая 2024, в 21:12
10000 руб./за проект