• 首页|
  • Community
    Articles Topics Q&A
    Learn
    Course Programming Dictionary
    Tools Library
    Development tools Website Source Code PHP Libraries JS special effects Website Materials Extension plug-ins
    AI Tools
    Leisure
    Game Download Game Tutorials
    search
    English
    简体中文 English 繁体中文 日本語 한국어 Melayu Français Deutsch
    Login
    singup
    Table of Contents
    Hello World
    Home Database Mysql Tutorial Eclipse+Tomcat+Mysql构建J2EE开发环境(原创)_MySQL

    Eclipse+Tomcat+Mysql构建J2EE开发环境(原创)_MySQL

    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    Jun 01, 2016 pm 01:12 PM

    Tomcat

    原文转载自:http://blog.csdn.net/wdwgr/article/details/1586155

    学习j2ee的门槛就是开发环境的配置问题,没有开发环境感觉无从下手,我就是因为这个而苦恼了好长时间啊,最后我选择了eclipse+tomcat+mysql,网上也有许多有关开发环境配置的文章,不过说的都不够详细,我试着自己总结了一下,经过2天的配置终于把环境配置好了,想想这两天的努力总算有了回报,来现在就和大家一起享受一下我的劳动成果吧!

    需要下载jdk,eclipse,tomcat,mysql,到哪下载就不说了,都是开源的

    1.安装jdk,按步骤一路next 就行,关键是安装完设置环境变量右键我的电脑——〉属性——〉高级——〉环境变量——〉系统变量:添加一下环境变量:(假如你的jdk安装在c:根目录下):

    JAVA_HOME:C:/jdk;

    Classpath=.;%JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar;(.;不能少,因为他代表当前路径)

    Path=%JAVA_HOME%/bin

    小插曲:(CLASSPATH是什么?它的作用是什么?
        它是javac编译器的一个环境变量。
        它的作用与import、package关键字有关。
        当你写下improt java.util.*时,编译器面对import关键字时,就知道你要引入java.util这个package中的类;但是编译器如何知道你把这个package放在哪里了呢?所以你首先得告诉编译器这个package的所在位置;如何告诉它呢?就是设置CLASSPATH啦 :) 如果java.util这个package在c:/jdk/ 目录下,你得把c:/jdk/这个路径设置到CLASSPATH中去!当编译器面对import java.util.*这个语句时,它先会查找CLASSPATH所指定的目录,并检视子目录java/util是否存在,然后找出名称吻合的已编译文件(.class文件)。如果没有找到就会报错!
        CLASSPATH有点像c/c++编译器中的INCLUDE路径的设置哦,是不是?当c/c++编译器遇到include 这样的语句,它是如何运作的?哦,其实道理都差不多!搜索INCLUDE路径,检视文件!
        当你自己开发一个package时,然后想要用这个package中的类;自然,你也得把这个package所在的目录设置到CLASSPATH中去!
        CLASSPATH的设定,对JAVA的初学者而言是一件棘手的事。所以Sun让JAVA2的JDK更聪明一些。你会发现,在你安装之后,即使完全没有设定CLASSPATH,你仍然能够编译基本的JAVA程序,并且加以执行。)

    接着可以写一个程序测试一下安装是否成功:

    public class Test{

             public static void main(String args[]){

                       System.out.println(“hello world.”);

             }

    }

    将以上程序保存为Test.java,打开命令提示符窗口,cd到你这个程序所在的文件夹,输入以下命令:

    Javac Test.java回车//编译程序

    Java Test 回车//解释程序

    此时若看到输出为hello world.说明安装成功,若编译未通过再仔细检查一遍环境变量的设置

    2.安装tomcat,非常容易不做介绍,安装完后右键我的电脑——〉属性——〉高级——〉环境变量——〉系统变量:添加一下环境变量:(假如你的tomcat安装在c:/根目录下)

    CATALINA_HOME=C:/tomcat;// catalina 就是Tomcat服务器使用的Apache实现的servlet容器的名字

    CATALINA_BASE=C:/tomcat;

    TOMCAT_HOME=C:/tomcat;

    然后修改环境变量中的classpath,把tomcat安装目录common/lib下的servlet.jar追加到classpath中去,修改classpath如下:

    Classpath=.;%JAVA_HOME%/lib/dt.jar;

                       %JAVA_HOME%/lib/tools.jar;

                      %CATALINE_HOME%/common/lib/servlet.jar;

    接下来可以启动tomcat了,在IE中访问http://Localhost:8080,如果看到tomcat欢迎界面的话,恭喜你安装成功了;

    3.安装mysql,我用的是免安装版的(我比较喜欢绿色软件)既然是免安装的当然要进行一些设置拉,如下:

    (1)解压 mysql-noinstall-5.0.27-win32.zip 到 D:/mysql5

    (2)在d:/mysql下建立文件 my.ini内容如下:

                       #========================================

    [WinMySQLAdmin]

    #一定要使用正斜杠 / 表示路径

    Server=D:/mysql5/bin/mysqld-nt.exe

     

    #支持中文的记录

    default-character-set=gb2312

     

    [client]

    #支持中文的记录

    default-character-set=gb2312

     

    [mysqld]

    basedir=D:/mysql5

    datadir=D:/mysql5/data

     

    character_set_server = utf8

     

    #支持中文的记录

    default-character-set=gb2312

     

    #支持事务的引擎

    default-storage-engine=INNODB

     

    #========================================

    (3)进入到d:/mysql/bin 安装系统服务

             安装服务命令:

                       D:mysql/bin>mysqld-nt.exe --install(注意一定是  --install,而不是  -install)

             进入命令提示符窗口cd 到:d:/mysql/bin

             输入以下命令:

             Mysql-nt –install

             Mysql –uroot –p

    出现password: 再回车,表示密码为空,现在就进入了mysql 提示符了,至此我们的mysql 已经安装成功;

    4.安装eclipse,直接解压缩,(我把它放在D:/Program Files/eclipse下)但是不要高兴得太早,这个只是一个单一的eclipse,要安装插件plugins才能发挥出它的强大的功能,在这里我们要用到的插件有tomcatplugin(因为我们要与tomcat合作),mysqlplugin(用来连接数据库)

    ,其他还有很多我们这里就不介绍了

    Tomcat软件包:com.sysdeo.eclipse.tomcat

    Mysql软件包:net.sf.jfacedbc_2.2.1

    如何安装这些插件呢?很简单:直接把他们解压缩到eclipse 安装目录下plugins 文件夹下面就ok了,( 记得还要把eclipse安装目录configuration目录下面的org.eclipse.update文件夹删除,要不eclipse不能加载你添加的插件)

    这些工作做完后

    打开eclipse ———Window ————〉preferences,点左边目录下的tomcat选项,对应右面要求你进行设置,首先选择你安装的tomcat 版本一定要和你安装的版本对应阿,Tomcat home选择tomcat的安装目录,再展开tomcat, JVM Settings——jre选择jdk(选jdk而不是jre,是因为jdk除了有java的运行环境还有java程序所需要的类,而jre只有运行环境。
    ),点击apply,重新启动eclipse,看到功能栏上多出了三只小猫,是不是很高兴,让我们来测试一下tomcat吧:

    编写程序
      (1).创建一个Tomcat项目
      右击“包资源管理器”窗口中的空白处,新建->Tomcat Project, 在项目名中填写项目名字,在这里我填tomcat_test,点击“完成”即可。
      (2).创建一个JSP页面
      在包资源管理器中,右击“tomcat_test”,新建->文件, 在文件名中填写HelloWorld.jsp(扩展名不能缺),在文本编辑窗口输入如下代码:

      


      
      
      

    Hello World


      
      
      然后保存。接着启动tomcat,那样只要你在浏览器窗口中输入http://*.*.*.*:8080/tomcat_test/HelloWorld.jsp浏览器就会显示“Hello World”,这样说明你的jsp页面部署发布成功(*.*.*.*是指安装了tomcat服务器的主机IP地址).

     

    5.剩下的就是连接数据库了,也很简单下载mysql-connector-java-3.2.0-alpha-bin.jar直接将其放在C:tomcat/commen/lib目录下,然后再把它添加到环境变量中去,在环境变量中添加C:/tomcat/commen/lib/mysql-connector-java-3.2.0-alpha-bin.jar;即可

     

    我们的配置工作到现在基本上算是大功告成了,接下来我们就来测试一下:首先确保你的数据库中有个test表,依照我们创建的第一个jsp页面那样新建个工程Test,添加一个.jsp文件,取名为test.jsp,添加如下代码:

        try{

           Class.forName("com.mysql.jdbc.Driver").newInstance();//装载数据库

           }

           catch(ClassNotFoundException error){

            System.err.println("Unable to load the JDBC/MYSQL driver."+error.getMessage());

           System.exit(1);

           }

       

        String url ="jdbc:mysql://localhost/test?user=root&password=";

        //假设test是你的数据库

        Connection conn=null;

        try{

    conn = DriverManager.getConnection(url);

           }

           catch(SQLException error)

           {

               System.err.println("Cannot connect to the database."+error);

               System.exit(2);

           }

    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

        String sql="select * from pet";//一般将查询语句赋值给一个String对象

        //从test表读数据

        ResultSet rs=stmt.executeQuery(sql); //

        while(rs.next()) {%>

        您的第一个字段内容为:

        您的第二个字段内容为:

        

        

        

        stmt.close();

        conn.close();

        %>

        

        

    然后保存,启动tomcat,打开IE,输入http://127.0.0.1:8080/Test/test.jsp,输出了你数据库中的数据了吗?

    恭喜你可以享受一下你辛苦的劳动成果了(文章中涉及到的插件如果找不到,可以给我发邮件,wdwgr@163.com


    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Show More

    Hot Article

    How to fix KB5055523 fails to install in Windows 11?
    4 weeks ago By DDD
    How to fix KB5055518 fails to install in Windows 10?
    4 weeks ago By DDD
    Roblox: Grow A Garden - Complete Mutation Guide
    3 weeks ago By DDD
    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    How to fix KB5055612 fails to install in Windows 10?
    3 weeks ago By DDD
    Show More

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Show More

    Hot Topics

    Java Tutorial
    1664
    14
    CakePHP Tutorial
    1422
    52
    Laravel Tutorial
    1316
    25
    PHP Tutorial
    1268
    29
    C# Tutorial
    1240
    24
    Show More
    Related knowledge
    When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

    Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

    MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

    MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

    MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

    MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

    MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

    The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

    MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

    MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

    Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

    InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

    MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

    MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

    Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

    MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

    See all articles

    Public welfare online PHP training,Help PHP learners grow quickly!

    About us Disclaimer Sitemap

    © php.cn All rights reserved