How to print the bean to the html page

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.