Application of JavaBean in JSP

Source: Internet
Author: User
Tags apache tomcat
Maybe every day is a new start ..
I was busy for a JavaBean for a day yesterday. But the problem still solved. Today I feel quite fulfilled, so I decided to write down my experiences and share them with you ..
First, let's look at a simple JavaBean class, userinfo. java.
Package com. Lili;
Public class userinfo
{
Public userinfo (){}
Public userinfo (string name)
{
This. Name = Name;
}
Public void setname ()
{
This. Name = Name;
}
Public String getname ()
{
Return name;
}
Private string name;
}
In short, a constructor with no parameters is essential... if you forget it, it will definitely make an error ..
Next, let's take a look at the Standard Operating element JSP: usebean that applies JavaBean in JSP .. this element is used to reference the Java Bean operation syntax on the JSP page for a brief introduction. <JSP: usebean id = "name" Scope = "Page | request | session | application class =" classname "/> you don't need to talk about what it means.
In my program, <JSP: usebean id = "userinfo" class = "com. Lili. userinfo">
Now let's take a look at <JSP: setproperty> and <JSP: getproperty>. One is to set the attribute values in the bean, and the other is to get the attribute values in the bean. Here I will mainly talk about the parameters in <JSP: setproperty>.
Of course, in setproperty, we should first point out the bean name. That is, name.
Then, the name of the property to be set is property. When property = "*", it indicates all the property values.
Then the PARAM and value attributes that cannot be included in JSP: setproperty ..... is value a value .. for example, if you want to set the name in bean to "Lili", you can use <JSP: setproperty name = "userinfo" property = "name" value = "Lili">
Param is the meaning of the parameter .. that is to say, you can assign a parameter value to the specified property. If the username value of a parameter in the program is "Lili", you can use <JSP: setproperty name = "userinfo" property = "name" Param = "username"> to set the name value ..
In fact, there is no technical content mentioned above .. in fact, the most important thing to note when using Javabean is. the class is stored... this may happen to every newbie .. when I have worked hard on the code .. waiting for your achievements to be displayed on the web page .. we have encountered the annoying value for the usebean class attribute... is invalid .. this attack is fatal to us .. there are two main problems in this situation .. the format of the JavaBean file is incorrect .. first, check the JavaBean to see if it meets the specifications. At least constructors without parameters are required .. if there is no problem with JavaBean, let's take a look. the path where the class is stored .. assume that you are using Apache Tomcat .. I am using 5. 59 .. I don't know what will happen to other versions .. you want. class is stored in the classes directory under the web-info directory .. of course, the corresponding package name is required .. let's talk about it in detail .. here I assume you have not learned how to set your working directory .. most new users are estimated to stay at this stage .. suppose our working directory is in the JSP-examples directory of webapps in tomcat5.5 .. in JSP-examples, we create our own directory testbean, which contains testbean. JSP file .. testbean. where should I place the JSP an for JSP .. let's look at the userinfo class .. it should be in the com. in Lili, create a com folder under the web-INF directory of JSP-examples, create Lili in COM, and then compile userinfo. put the class in Lili, OK, and then process your own JavaBean ..
I am so arrogant. I don't know if it is helpful to the people who see the post. If you have any questions, please contact me. make progress together ..
Related Article

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.