美文网首页Pentest
Linux下搭建Tomcat+MySQL+JSP

Linux下搭建Tomcat+MySQL+JSP

作者: cws | 来源:发表于2016-07-12 18:52 被阅读474次
    安装环境为:CentOS-6.5-x86_64-minimal
    

    安装mysql

    sudo yum install mysql mysql-server mysql-devel

    install_mysql.png creat_db_tomcat.png grant_db_tomcat.png

    安装jdk和tomcat

    1. 创建安装jdk和tomcat的文件夹


      mkdir_java_tomcat.png
    1. 下载安装包并解压安装
      jdk包可在http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载
      tomcat包可在http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz 下载
      download_tomcat.png
    cp_jdk_tomcat_to_opt.png add_java_env.png java_version.png

    简单配置tomcat

    config_tomcat1.png config_tomcat2.png

    启动tomcat

    start_tomcat.png see_tomcat_index.png

    连接数据库

    驱动可在http://dev.mysql.com/downloads/connector/j/ 下载

    tomcat_copy_mysql_driver.png
    [reber@WYB ~]$ vim /opt/tomcat/apache-tomcat-8.0.36/webapps/ROOT/a.jsp
    <%@page contentType="text/html;charset=utf-8" import="java.sql.*" %>
    <%
        String driver = "com.mysql.jdbc.Driver"; 
        String url = "jdbc:mysql://localhost:3306/tomcat"; //数据库web
        String user = "tomcat"; 
        String password = "123456"; 
        try { 
            Class.forName(driver); 
            Connection conn = DriverManager.getConnection(url, user, password);
    
            if(!conn.isClosed()) 
                out.println("数据库连接成功!"); 
            conn.close(); 
        } 
        catch(ClassNotFoundException e) { 
            out.println("找不到驱动程序"); 
            e.printStackTrace(); 
        } 
        catch(SQLException e) { 
            e.printStackTrace(); 
        } 
    %>
    
    
    tomcat_conn_mysql.png

    相关文章

      网友评论

        本文标题:Linux下搭建Tomcat+MySQL+JSP

        本文链接:https://www.haomeiwen.com/subject/piksjttx.html