My first configuration javabean

zhaozj2021-02-16  59

I am using Tomcat 5.018, JDK: 1.4.2

The installation path I use is: C: / Tomcat5 C: / JDK142

The settings in the system variable are:

Classpath:.; C: /J2SDK142/lib/dt.jar; c: /j2sdk142/lib/tool.jar; C: / J2SDK142 / JRE / LIB / EXT; C: /J2SDK142/LIB/mm.mysql-2.0. 4-bin.jar; c: / tomcat5 / common / class; c: / tomcat5 / common / lib; c: /tomcat5/common/lib/servet-api.jar; c: / tomcat5 / webapps / root / web- INF / CLASSES

PATH: C: / J2SDK142; C: / J2SDK142 / bin

Java_Home: C: / J2SDK142

Tomcat_home: C: / Tomcat5

The upper side is the basic configuration, the following wait at the right go home and write :)

I still now now everyone's javabean program gives you a new demo. At the same time, I suggest that if you are not familiar with friends, you can copy the procedure below. I have debugged:

There are still some attention before reading the program: If you don't configure the E: /TOMCAT5/conf/server.xml file, the system will run the default program to run the path:

E: /tomcat5/webapps/root/index.jsp

If you change, you care about this sentence.

It is specified that the root path can be configured with a virtual host. We will follow the configuration of the virtual host. Now there is an impression in your mind. Everything is not moving. Follow the default us to start writing:

/ * Tax.jsp * /

<% @? page? import = "Tax.Taxrate"%> <% @? page? language = "java"%>

Before modification: Product: <% = TaxBean.getProduct ()%> Tax rate: <% = TaxBean.Getrate ()%>

<%? TAXBean.SetProduct ("A002"); TAXBean.Setrate (20.5);%> After modification: Product: <% = TaxBean.getProduct ()%> Tax rate: <% = TaxBean.Getrate ()%>

/ * Tax.jsp over * /

/ * TaxRate.java * /

package tax; public class TaxRate {String Product; double Rate; public TaxRate () {this.Product = "A001"; this.Rate = 5;} public void setProduct (String ProductName) {this.Product = ProductName;} public String GetProduct () {Return (this.product);} public void set (double.rate = rate (} public double getrate () {return (this.rate);}} / * Taxrate.java over * / Below is the problem of the path.

Note that the Tax.jsp here is placed in the root directory:

E: / Tomcat5 / WebApps / root

All .java .class is placed in the default path of Tomcat5.018, that is, in the classes directory:

E: / Tomcat5 / WebApps / Root / Web-INF / CLASSES

We are here to explain the part of the main path in the Taxrate.java file.

Package Tax; is the first line program. It specifies the parent directory of the current class file. It is equivalent to establishing a TAX directory under the E: / Tomcat5 / WebApps / Root / Web-INF / CLASSES, and now .java .class is under the TAX directory under the CLASSES directory. This is to better plan your own package.

Tax.jsp

<% @? page? import = "Tax.TaxRate"%>

This sentence is to introduce a package. TAX is undoubtedly the catalog of our establishment. Taxrate is the file we generated for Taxrate.class. Use in the middle of the directory. Replace. This is true for how many of the directorys.

The value here is that the value of the ID is when the lower method is called, which bean is used to indicate which bean belongs to. You can see, for example: taxbean.getProduct ();

Scope About the life cycle, we will not say much now. You will write this way.

Class This place must write correct. Its meaning is one of the above IMPORT. In fact, it is indicated here, which one is omitted. But sometimes according to the container, some pick. So there is no mistake to write.

Then you run. There should be no problem. According to my path. What I need to do is:

http://127.0.0.1:8080/tax.jsp

The correct result is:

Before modified: Product: A002 Tax rate: 20.5 After the revision: Product: A002 Tax rate: 20.5

Finally Note: Java is sensitive to case sensitive. At the same time, I hope everyone will pay attention to writing formats. Although the writing format has no significance to the program itself. But a good writing format is easy to browse, check the error, and avoid unnecessary writing errors.

I don't have to understand how much you can understand here. The at least is to tell you an example of a success. He is nothing, but it is very good for learning confidence in you to establish.

Big cabbage core

February 17 0:21, 2004

QQ: 20512916

转载请注明原文地址:https://www.9cbs.com/read-22354.html

New Post(0)