" Declare a class that is valid within the JSP page, that is, you can use this class to create objects in the Java program part of the JSP page."/> " Declare a class that is valid within the JSP page, that is, you can use this class to create objects in the Java program part of the JSP page.">
A class is a user-defined type, also called a class type. Each class contains a data description and a set of functions that manipulate data or pass messages. Instances of a class are called objects.
You can declare a class between "<%!" and "%>". This class is valid within the JSP page, that is, it can be used in the Java program part of the JSP page. Create objects using this class.
#In the following example, we define a Circle class, the object of which is responsible for finding the area and sum of the circle perimeter. When the client submits the radius of the circle to the server, this object is responsible for calculating the area and circumference of the circle.
<%@ page contentType="text/html;charset=GB2312"%> <%@ page import="java.io.*"%> <HTML> <BODY BGCOLOR=cyan> <FONT Size=4> <P>请输入圆的半径: <BR> <FORM action="" method=get name=form> <INPUT type="text" name="cat" value="1"> <INPUT TYPE="submit" value="送出" name=submit></FORM> <%! public class Circle { double r; Circle(double r) { this.r=r; } double 求面积() { return Math.PI*r*r; } double 求周长() { return Math.PI*2*r; } } %> <% String str=request.getParameter("cat"); double r; if(str!=null) { r=Double.parseDouble(str); } else{ r=1; } Circle circle=new Circle(r); %> <p>圆的面积是: <BR> <%=circle.求面积()%> <p> 圆的周长: <BR> <%=circle.求周长()%> </FONT> </BODY> </HTML>
The above is the detailed content of What is jsp class. For more information, please follow other related articles on the PHP Chinese website!