Seemingly simple, is the use of a class, but the use of the time a lot of problems.
1, the use of bean package
There is a package * * * At the beginning of the Java file that defines the bean. But where is it exactly? If this problem is not clear, the appropriate bean class will not be found.
The first is that this class should be placed under web-inf/classes (do not create the Web-inf web_inf), and then you can create the package, which is actually a folder, and then define the folder name based on the package used by packages. For example, the package bean, which means to create a bean folder under the Classes folder, and then put the JavaBean (which is actually the class) and put it in this folder. This allows the server to find JavaBean based on the package name.
2. I have collected the request sent over, how to add the parameters in the request to the bean?
<%=%> represents the output, I try not to ah?
How do you assign a value?
Like what:
Assuming the value of name is passed,
<jsp:setproperty name= "test" property= "name" value=<%=name%>/>
This sentence is not a pass.
The correct assignment statement is <jsp:setproperty name= "test" property= "name" value= "<%=name%>"/>
3, write <jsp> instruction, pay attention to the writing end character/
OK, that's the thing to note.
Let's review how to use the JavaBean.
1, first we define the JavaBean.
2, then is the need to refer to the page to introduce this javabean,
3, when we use <jsp:usebean id= "test" class= "Test" >, is actually created a bean instance, equivalent to: Test test=new test ();
4, using SetProperty and GetProperty equivalent to call Test.setxxx () and test.getxxx (), so you can understand why they have the Name property, the actual Name property is to point to the creation of the bean instance
Instance:
student.jsp
<%@ page contenttype= "text/html; Charset=utf-8 "%>
registerstudent.jsp
<%@ page import= "java.util.*" import= "bean. Studentbean "contenttype=" Text/html;charset=utf-8 "%>Sutentbean.java
Package Bean;public class studentbean{ private String name; Private String address; Private String phone; public void SetName (String name) { this.name = name; } Public String GetName () { return this.name; } public void setaddress (String address) { this.address = address; } Public String getaddress () { return this.address; } public void Setphone (String phone) { this.phone = phone; } Public String Getphone () { return this.phone; } Public Studentbean () { this.name= "user"; this.address= "Address"; This.phone= "Phone"; } }
The JavaBean of JSP