JavaBean application steps in JSP

Source: Internet
Author: User
Tags tomcat

When writing JSP Dynamic Web design, how to apply JavaBean? Below I explain step-by-step, explain, this is only my experience, may not be completely summed up, of course I have successfully compiled and used correctly.

(the diagram below)

JavaBean. Class byte files can be placed in the classes directory of Tomcat itself, but it is best to customize the directory to create the following directory in the current directory: .../web-inf/classes (for example, I used webapps/example/. Web-inf/classes/. In the illustration above, the Hello.java used in the example that I cited, which has been compiled, generated hello.class byte files and placed in the Classes folder, is not like the position of the JavaBean that makes any other Web service file available, directly Put the. class byte file into the classes directory that you already have in Tomcat. But now that the high version of Tomcat does not have these directories, then the application JavaBean, of course, to build these directories themselves.

When creating a directory, note that the folder name is Web-inf, not wen_inf, note that the middle of the bar to write the right; the folder name is classes and not the name of the package under Class;classes also note that it is the same as the package name in your JavaBean, for example, You have the following statement in the JavaBean file: Import Bao means that you have introduced a package named Bao, then the package name (folder name) under the Classes folder should be Bao.

Then write a good javabean, compile. Here to say how to compile JavaBean in DOS: Start-run-enter cmd--via CD. or the CD into the JavaBean directory (such as the image of the Hello.java file, I put it in the Mypao, then in DOS, it is necessary to enter the directory to compile it), and then enter the command: Javac After Hello.java, you can get the Hello.class byte file generated in the Mypao package and compile it. If the JavaBean has been modified, remove the old. class file first and recompile the JavaBean.

You can then use it in your JSP. I'm copying the code to explain it, a1.jsp file code is as follows:

﹤%@ page contentType="text/html;charset=GB2312" %﹥
﹤%@ page import="mypao.Hello"%﹥
﹤!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"﹥
﹤html xmlns="http://www.w3.org/1999/xhtml"﹥
﹤head﹥
﹤meta http-equiv="Content-Type" content="text/html; charset=gb2312" /﹥
﹤title﹥JavaBean的应用﹤/title﹥
﹤/head﹥
﹤body bgcolor="#9900FF"﹥
﹤center﹥
﹤p﹥﹤h3﹥下面用JavaBean显示:﹤/h3﹥﹤/p﹥
﹤jsp:useBean id="hh" class="mypao.Hello" scope="page"﹥ ﹤/jsp:useBean﹥
﹤%=hh.getX()%﹥
﹤/body﹥
﹤/html﹥

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.