Call JavaBean in JSP

Source: Internet
Author: User

JSP is short for Java Server Pages. It is an excellent dynamic website development language and is now favored by more and more programmers. Among various JSP applications, Jsp + JavaBean combination has become a standard. This article describes JSP and JavaBean, create JavaBean, and call JavaBean in JSP. Next, let's take a look at how Jsp is combined with JavaBean.

I. Introduction to JSP and JavaBean

JSP is a new type of dynamic web page programming technology pioneered by Sun. JSP source code can be directly embedded into HTML, making program development more simplified and fast. JSP is a Web page technology based on JAVA on the server. It adds Java program fragments and some JSP tags to traditional HTML web pages. The application JSP program can separate content generation and display, and can also use reusable components. JavaBean is a class placed on the JSP server background. It encapsulates some data and methods. This class is compiled by a Java file, JSP directly calls the data and methods through JavaBean. For example, for a common shopping website, the shopping cart operation inside is a JavaBean. After you have written some methods required for shopping operations, JSP can directly call these methods through JavaBean. The advantage of this is that when the shopping demand changes, you only need to change the JavaBean method.

Ii. Creation of JavaBean

To create a JavaBean, first install and set JDK, and then create a Java file named MyJavaBean. java. Finally, compile the MyJavaBean. java file.

Install and set JDK. JDK is short for Java Development Kit. It is a development environment used to build applications, applets, and components released on the Java platform. The version used in this article is 1.5.0. The download address is http://java.sun.com/j2se/1.5.0/download.jsp. Double-click the installer to install the SDK by default. After installation, configure jdk. First, find the jdk bin directory. For example, the default installation path is C: \ Program Files \ Java \ jdk1.5.0 _ 03 \ bin. Copy the path name, open the "properties" Window of "My Computer", find "advanced", click "environment variable", find "PATH" in the system variable, and double-click "PATH" record, in the "Edit System variables" window, add a semicolon and the jdk bin directory at the end of the variable value, for example,; C: \ Program Files \ Java \ jdk1.5.0 \ bin. Click "new" to create a new system variable named java_home. The variable value is C: \ Program Files \ Java \ jdk1.5.0, which is the default installation path ). Click "new" and create a new system variable named classpath. The variable value is C: \ Program Files \ Java \ jdk1.5.0 \ lib \ dt. jar; C: \ Program Files \ Java \ jdk1.5.0 \ lib \ tools. jar. Finally, press OK to exit. In this way, JDK is installed and configured.

3. Call JavaBean in JSP

To call JavaBean in JSP, you must create a JSP file named JavaBean. jsp, and then install and configure the Tomcat server.

1. Create a JSP file named JavaBean. jsp

2. install and configure the Tomcat server
The Tomcat service version used in this article is 5.0.28, the download URL is http://archive.apache.org/dist/tomcat/tomcat-5/archive/, after the download, unzip the jakarta-tomcat-5.0.28 to the directory C: \ tomcat-5.0.28 is installed. After installation, configure tomcat. Find the bin directory of Tomcat. For example, if the default path is C: \ tomcat-5.0.28 \ bin, copy the path name, and open the "properties" Window of "My Computer, find "advanced", click "environment variables", find "PATH" in the system variables, double-click the "PATH" record, and the "Edit System variables" window is displayed, add a semicolon and the bin directory of Tomcat at the end of the variable value, such as:; C: \ tomcat-5.0.28 \ bin. Click "new" to create a new system variable named tomcat_home. The variable value is C: \ tomcat-5.0.28. Finally, press OK to exit.

3. Call JavaBean in JSP
To call JavaBean in JSP, first copy the compiled JavaBean folder JavaBean to the. \ webapps \ ROOT \ WEB-INF \ classes \ folder of Tomcat after installation. Copy the JavaBean. jsp file to the. \ webapps \ ROOT \ folder of the installed Tomcat. Open the bin directory of tomcat-5.0.28 and double-click the "startup. bat" MS-DOS batch file to start the tomcat server.

Through the above steps, you can easily call JavaBean in JSP. I hope this article will help JSP programmers and JSP developers learn about calling JavaBean in JSP, and help them learn how to get started with JAVA.

  1. Establishment of JSP development environment
  2. Brief Introduction to JSP environment Configuration
  3. JSP, ASP, and PHP security programming
  4. Integrate JSP and PHP in Apache
  5. Security issues of JSP and Servlet applications

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.