Home > Java > javaTutorial > body text

What is jsp class

(*-*)浩
Release: 2022-06-07 14:20:34
Original
5241 people have browsed it

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.

What is jsp 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>
Copy after login

The above is the detailed content of What is jsp class. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!