Deploy the JSP development environment in Ubuntu, Eclipse + Mysql + JDBC

Source: Internet
Author: User

Deploy the JSP development environment in Ubuntu, Eclipse + Mysql + JDBC

Install JDK1.7 first. Create an Eclipse for JavaEE program.

Then, enter Ctrl + Alt + T to open the terminal, and enter the following command, which is the same as running M -- Mysql in LAMP to improve the Mysql service. Enter the command, wait for download, set the database password, and wait for installation. For more information, see the previous "[Linux] In Ubuntu layout LAMP environment" (http://www.bkjia.com/ OS /201504/392319.html ).

sudo apt-get install mysql-server mysql-client

Do a good job in Mysql WorkBench to make Mysql graphical.

In Linux, php is deployed in the same way as jsp in many places, especially the same database Mysql.

Next, there are different aspects of Jsp and php.

1. Download and install Tomcat, and configure and deploy Tomcat in Eclipse

1. First, we need a Tomcat. Go to Tomcat's official website http://tomcat.apache.org/download-70.cgiand select the Linux version of Tomcat7.0's Core version.

2. decompress the package directly to the main folder to facilitate management without changing the file permissions. Delete the decompressed file. In fact, after decompression, the items in Tomcat are exactly the same as those in Windows. If you start Tomcat manually, use. sh to start and close Tomcat.

3. Open the Java EE interface under Eclipse, right-click the blank area on the Server Tab below, and add a Server.

4. Find Tomcat7 and click Next.

5. Then, in the browsing process, select the Tomcat path, which is the place we just decompressed. Then remember to select JRE for jdk1.7. Do not use the default JDK of Eclipse, or you will not know what the problem will be.

6. Later, because there is no Java Web project, you can directly choose to complete it.

7. Double-click the server we just created and configure Tomcat.

8. In the open window, set the "Use Tomcat Installation (...)" field to "Server Locations (...) then, the compiled server will change. Then, change the Deploy Path to the default webapps of Tomcat, save the settings, and close the button.

2. Create a JavaEE project to connect to the Mysql database

1. Create a JavaEE Project, and create a Dynamic Web Project in the blank area of the Project Explorer tab on the left.

2. enter the name of the JavaWeb project, such as javawebtest. Click Next. Do not click Finish in a hurry.

3. As the Web project created in [Javaweb] Eclipse for JavaEE automatically generates the web. xml (click to open the link) to automatically generate the web. to enable the Java Web project to start directly.

4, after, we want to download a mysql-connector-java-5.0.8-bin.jar thing, put the lib under the WEB-INF under WebContent, so that the Web project can connect to the Mysql database. This is also an official Mysql file. Directly open its official website http://dev.mysql.com/downloads/connector/j/5.0.html (click to open the link) This official website is doing very bad, if the speed is not good, the drop-down menu is not responding. Select the old version, and then select a non-platform dependent version. Ubuntu can also decompress the zip file.

5, unzip, although there are a lot of documents, but as long as the mysql-connector-java-5.0.8-bin.jar in the Java Web project under the WebContent \ WEB-INF \ lib folder can be.

6. Refresh the javawebtest project under the Eclipse project and create a jsp file under the webcontent folder.

7. Name it test. jsp. Click here to complete it.

8. Write the following code in it:

 

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ page import="java.sql.*" %>
<% Connection con = null; try {Class. forName ("com. mysql. jdbc. driver "); // Where test is the database to be linked, user is the database username, and password is the database password. // 3306 is the mysql port number, which is usually the long string of parameters following this // to prevent garbled characters, you do not need to add a set names UTF8 String url = "jdbc: mysql: // localhost: 3306/test? UseUnicode = true & characterEncoding = utf8 & useOldAliasMetadataBehavior = true "; String user =" root "; String password =" root "; con = DriverManager. getConnection (url, user, password);} catch (Exception e) {e. printStackTrace ();} out. println ("database connection successful! "); %> It is actually the content of connecting to the Mysql database using java. Note that java is introduced in the header. SQL. *, For details, see "[Mysql] Java Mysql database addition, deletion, modification query, Java System class" (http://www.bkjia.com/database/201502/375536.html ). After writing the code, right-click the Tomcat Server under the Server and choose add project.

 

9. Add the javawebtest project to Tomcat and start the Tomcat server.

10. When you see the prompt that Tomcat is successfully started on the console, you can open the built-in wild fox Zen browser.

11. Enter localhost: 8080/javawebtest/test. if jsp displays "Database Link succeeded", it indicates that the JSP development environment has been successfully deployed in Ubuntu, And the JSP project can be successfully connected to the database!

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.