A friend asked this question in the chinaasp Forum. the webmaster wrote a simple example to demonstrate how to use the out method in bean.
The out method is actually a JspWriter object hidden in a jsp file. Generally, it can be directly output in jsp, such as out. println ("test ");
However, this will cause problems in bean. Therefore, we need a little trick to use all the out methods by passing the out object to bean.
The following code provides an idea:
<Jsp: useBean id = "bean" class = "XXX" scope = "XXX"/>
<%
Bean. setOut (response );
Bean. test ();
%>
Some code in bean
Import javax. servlet. jsp .*;
JspWriter out = null;
Public void setOut (JspWriter out)
{
This. out = out;
}
Public void test ()
{
Out. println ("<font size = 12> hello </font> ");
}
Similarly, other objects such as response and request can be passed to the bean in this way. The method is the same, so we will not give an example.