JavaBean the difference between calling and using JSP action tags with JSP

Source: Internet
Author: User

JavaBean classes can be instantiated and used with JSP action tags.

 1  <!--The following sentence is a reference to the JavaBean class person, the instance of the reference is P2-->2  <jsp:usebean id= "P2" class  = "Com.kaly.bean.person" ></jsp: Usebean>3  <!--the next line is to assign a value to each member of the P1, where "*" means to assign the value of the request form to the person reference P2, The prerequisite is that all names in the form must correspond to the name of the member in the person-->4  <jsp:setproperty property= "*" Name = "P2"/>5  <!--The following lines are the values of each member in P2, which is actually called the Get method-->6  Name: <jsp:getproperty property= "name" Name= "P2"/><br>7  Gender: <jsp:getproperty property= "Sex" name= "P2"/><br>8  Age: <jsp: GetProperty property= "Age" Name= "P2"/><br>9  info: <jsp:getproperty property= "Info" name= "P2"/><BR> 

You can also use JSP code to instantiate it.

1<%2Person p3=NewPerson ();3P3.setname (Request.getparameter ("name"));4P3.setsex (Request.getparameter ("Sex")));5   //Integral number assignment needs to be transformed .6P3.setage (Integer.parseint (Request.getparameter ("Age")));7P3.setinfo (Request.getparameter ("info"));8Out.println ("Name:" +p3.getname () + "<br>");9Out.println ("Sex:" +p3.getsex () + "<br>");TenOut.println ("Age:" +p3.getage () + "<br>"); OneOut.println ("Info:" +p3.getinfo ()); A%>

You can see that there is almost no JSP statement using JSP action tags. On the one hand, it is recommended not to use JSP statements after web page redirection, on the other hand, developers do not want to have too many JSP statements in the Web page, so the reusable code is encapsulated in JavaBean way. Not only makes the webpage code not messy, avoids the error, also facilitates the maintenance, the efficiency is also relatively high.

The result of running two pieces of code together:

JavaBean the difference between calling and using JSP action tags with JSP

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.