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