tomcat,mysql,eclispe,jsp环境配置
环境
win7 32位,tomcat7.0.24,mysql5.0.77,jdk1.6.0
jdk配置:
环境变量:
CLASSPATH .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;
Path %JAVA_HOME%\bin
JAVA_HOME C:\Program Files (x86)\java\jdk1.6.0_20
测试
命令行:java,javac可正常执行,jdk配置成功
tomcat配置:
环境变量:
CATALINA_HOME D:\java\tomcat7042
CATALINA_BASE D:\java\tomcat7042
CLASSPATH %CATALINA_HOME%\lib\servlet-api.jar;
path %CATALINA_HOME%\bin;
测试
命令行:tomcat\bin\startup.bat
能打开http://localhost:8080 Tomcat配置成功
新建站点
webapps目录下新建文件夹命名为new
将ROOT中内容copy到new中
访问http;//localhost:8080/new
mysql安装
安装选择编码格式时选自己要的编码,这里用gbk
连接数据库注意要单独配置驱动,将mysql-connector-java-5.0.7-bin.jar放到D:\java\tomcat7042\webapps\自己站点名\WEB-INF\lib中,否则用代码连接时找不到驱动
测试
jsp代码测试
<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <% Class.forName ("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/com?user=root&password=nafio&useUnicode=true&characterEncoding=UTF-8"; Connection conn= DriverManager.getConnection(url); Statement stmt=conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); %> <html> <head> <title> Title </title> </head> <body> <% String num = ""; ResultSet rs=stmt.executeQuery("select * from gua" ); if(rs.next())num=rs.getString(2); rs.close(); %> 查询结果:<%=num %> </body> </html>