JSP tutorial (5)-use of JSPActions _ MySQL

Source: Internet
Author: User
Jsp: useBeanAction usage 1. Syntax: jsp: useBeanrequest | session | application {typepackage. class | beanName {package. class | % expression %} Use of typepackag jsp: useBean Action

I. syntax:
Id = "beanInstanceName"
Scope = "page | request | session | application"
{Class = "package. class" |
Type = "package. class" |
Class = "package. class" type = "package. class" |
BeanName = "{package. class | <% = expression %>}" type = "package. class"
}
{/> |
> Other elements

}

This action enables you to load a JavaBean into a JSP page. This is a very useful capability because it enables you to use reusable JAVA classes without sacrificing performance. The simplest syntax is to specify a bean:


  

This usually means that "the object of a class is instantiated by specifying a class and binding it to a variable named by id ". However, as we can see, you can specify a scope attribute so that the bean is not only associated with the current page. In this case, it is very useful to obtain a reference to an existing bean. In addition, a new bean is created only when there is no bean with the same id and scope. Now that you have a bean, you can modify it through jsp: setProperty, or use the name specified by the id to use scriptlet or call the method explicitly. When you say "this bean has an attribute of the X type called foo", you really mean "this class has a method called getFoo, which returns a value of the X type, another method is setFoo, which takes X as the parameter." This jsp: setProperty action will be detailed in the next unit, but now you can give a clear value and an attribute to indicate that this value is inherited from the request parameter, you can also just list attributes to indicate that this value should be inherited from parameters with the same name as the attribute name. You can obtain an existing jsp expression or scriptlet attribute by calling the applicable getXxx method or, more commonly, using JSP: getProperty action.

Note that the class specified for bean must be under the class path of the server rule, rather than the path of the class automatically loaded when the change occurs. For example, on Java Web Server, it and its classes must be in the class directory or in a jar file under the lib Directory, rather than in the servlets directory.

Let's take a very simple example. it loads a bean and sets/gets a simple string parameter.

BeanTest. jsp


Reusing JavaBeans in JSP





Reusing JavaBeans in JSP




Property = "message"
Value = "Hello WWW"/>
Message:

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.