Print text from java class method on .jsp page

I just try out the Java JSP form, I use the Java * .java class, there is a method in this class that prints String System.out.println("Message"); , I call this method from index.jsp, the message "Message" appears on the server console, but not in index.jsp, because System.out.println(); will not work in jsp file.
Edit: Question about how to send and show this message in my index.jsp?

+6
source share
1 answer

In JSP, you have an implicit out object. Use out.println() to print on web pages.

Additionally, inside HTML you can use <% = "Message"%> (or <% myMessage.toString ()%> for the same effect

UPDATE:

Either you are in a JSP (or servlet) or not. The object that receives the stream for writing HTML is the servlet * (explicit or compiled from JSP). If you can write from another class, you need to pass out this class and use it (you cannot write to a web page using System.out).

Be careful not to pass it to the business logic class, they must be incompatible with the user interface (i.e. they do not need to know that the user interface is HTML); this will be bad practice, as it will mix inner classes with external output.

+7
source

Source: https://habr.com/ru/post/914849/


All Articles