UseBean tag

I really got confused in the next two lines of First First Server and in the JSP book on page no. 349

  • This is a way of declaring and initializing the actual bean that you are using.

2. Declare and enter an intializea bean with

<jsp:useBean> <jsp:useBean id="person"class="foo.Person" scope="request"/>

In the first line, why did they call the attribute as an object?

Since the attribute is a name / value pair, bound to the scope, for example, request, session.

+3
source share
2 answers
<jsp:useBean id="person"class="foo.Person" scope="request"/>

This calls the default constructor for foo.Person

The person identifier allows you to link to Bean on the jsp page

<div>   
    <c:out value="${person.name}" />
</div>

Volume is the area for Bean foo.Person

JSP useBean .

, JavaBean .

package foo;

public class Person {

    private String name;

    public Person() {
        this.name = "jack"
    }

    public String getName() {
       return name;
    }

    public void setName(String n) {
        this.name = n;
    }

}

Person Bean , useBean Bean JSP.

+1
<jsp:useBean id="person" class="foo.Person" scope="request"/>

"" "foo.Person".

Apache Tomcat 6 Java:

  foo.Person person = null;
  synchronized (request) {
    person = (foo.Person) _jspx_page_context.getAttribute("person", 
                            PageContext.REQUEST_SCOPE);
    if (person == null){
      person = new foo.Person();
      _jspx_page_context.setAttribute("person", person,
                            PageContext.REQUEST_SCOPE);
    }
  }

_jspx_page_context is an instance of PageContext.

0

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


All Articles