Java servlet combined with MySQL to build java web development environment

The database used to learn servlet this time is mysql, and I'm ready to learn JavaWeb, so the article on JavaWeb will certainly continue to be updated later. I actually wanted to learn PHP a few days ago, but a friend reminded me to turn to JavaWeb.

Because I am currently working on mobile applications, I still intend to start with the data interface when learning Java. The process of this explanation will be very detailed... From the way I built it - the errors encountered in the middle - to the final data display, I will post them one by one.

1、 Install the Java Web development environment under ecplise:

This step is the same as the previous article java servlet + Oracle, so I directly post the address here

http://www.jb51.net/article/77065.htm

2、 Download Web server software Apache Tomcat 7.0:

Download the Java Web server support software Apache tomcat, and then unzip it to any path,

In fact, I suggest that you can create a folder for java servlet to store its files, because there are other files behind it Files such as jar package need to be placed. Here is my folder

3、 Create servlet web server environment / create servlet web project:

1: Add Web server environment

Ecplise -- > menu bar (Windows -- > preferences -- > server -- > runtime environment -- > Add

2: Create a dynamic web site and add servlet pages

Create a dynamic web site file - > New - > dynamic web project, and then directly next. After the jump, choose a name and finish the creation

Create servlet page: right click to select SRC - > New - > servlet creation page in the project

The following is a screenshot after creation:

In the screenshot above

In the helper package, one is the auxiliary class of MySQL, and the second is the JSON auxiliary class,

Inside the servlettest package is the servlet page

Dbinfo. In SRC folder The properties file is the connection auxiliary file of my own database. You can create this file on the desktop and then copy it to the SRC folder. Remember that the path must not be wrong,

Otherwise, the database connection will be used and an error will be reported The following is a screenshot of the contents of this file, which are all the information required for MySQL database connection

,

Here, our java servlet project and running environment are created

4、 Increase the required Jar package to Apache Tomcat 7.0 lib folder:

Here, I only use two jar packages for the time being, one is the driver package of MySQL, and the other is the auxiliary package of JSON. I'd like to make a screenshot for details

5、 Paste code screenshots and operation screenshots:

1: There are three methods in the servlet page. The first is the construction method of the class, which is generally not used. The second and third are the methods for processing data requests. The first is get, and the second is post, which restricts the way to access data. Post is more secure than get, but their implementation code is the same for those who write the interface...

Two classes encapsulated in the helper are used here, mysqlhelper and resulttojsontool. In fact, mysqlhelper also encapsulates methods for accessing stored procedures, and stored procedure access methods with out return parameters. I have written interfaces before, but I use them Net technology is really inefficient for writing interfaces without these two things. With it, you may need only one stored procedure for the task completed by 10 SQL statements.

2: Output effect

I plan to learn java well. In the future, I will spend most of my spare time studying Java, so I will continue to add articles on Java, and then it will involve setting up a java web running environment on Linux.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>