Examples of Tomcat+jsp+javabean

Source: Internet
Author: User
Tags tomcat
Js

1. Download and install Tomcat5.5


2. Download and install the Tomcat for Eclipse plug-in.

Unzip the downloaded plugin into Eclipse's plugins directory.
When you open eclipse, choose Windows-preferences, which will have a tomcat bar inside.
Tomcat version selected version5.x.
Tomcat Home Select Tomcat's post installation directory.
Advanced Tcomcat Base selected Tomcat in the Setup directory.
The JRE in JVM Settings typically automatically selects the version of the JRE installed on this computer. This is jre1.5.0_06.
Managerapp URL is automatically http://localhost:8080/manager in Tomcat Manager App
Username and password are filled in when Tomcat is installed.


3. You can now create a Tomcat project by Fild-new-tomcat Project. The project automatically creates a
The Web-inf directory previously classes,lib,src these three subdirectories. The compiled JavaBean class file is automatically generated
In the classes directory.


4. First create a JDBC subdirectory in the Tomcat-home WebApps directory. Call

is to use http://localhost:8080/jdbc/and then create a index.jsp file inside.


5. We then create a Web-inf subdirectory in the JDBC directory. You will then copy the three subdirectories below Web-inf in step three.


6. Open the browser input: http://localhost:8080/jdbc/can see the effect. Of course remember to start the Tomcat service.

The contents of the index.jsp file are as follows:
<title> A simple example of using JavaBean </title>
<% @page contenttype= "text/html; charset=gb2312 "%>
<%@ page import= "beans. JavaBean "%>
<body>
<%
JavaBean jb=new JavaBean ();
Jb.setname ("abc");
Out.println (Jb.getname ());
%>
</body>

===========================================================

The contents of the Javabean.java file are as follows:
Package beans;
public class JavaBean {
Private String name = NULL;
public void SetName (String name) {
THIS.name = name;
}
Public JavaBean () {
}
Public String GetName () {
return this.name;
}


Note: The inside character should note case sensitive.

This is a very simple example, mainly refers to the use of methods, feeling JavaBean is really good, I can use the pure Java language to write the business layer, so that the JSP is only the presentation layer, and through the JavaBean can also write the database operation of this piece, indeed very good.



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.