第1篇 Java Web开发基础篇
第1章 Java Web开发概述
1、Java语言
Jsp和Servlet技术都是用Java语言实现的,Java组件都是用Java开发的;
2、Java Web
B/S模式;
使用HTTP协议;
服务器把数据组织成HTML格式;
Web服务器:Tomcat,IBM WebSphere,Oracle WebLogic,Microsoft IIS(主要运用于.NET平台);
Jsp从内容上看就是HTML中加入Java脚本,Tomcat把Jsp页面翻译成Java文件,然后编译成Java class文件;
Jsp从本质上看就是一个Servlet;
第2章 搭建Java Web开发环境
1、JDK、JRE
JDK环境变量:
PATH:系统搜索可执行程序的路径;
CLASSPATH:搜索Java类路径;
JAVA_HOME:JDK安装目录;
D:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.6.0_22
D:\>echo %PATH%
c:\oracle\product\10.2.0\db_1\bin;C:\Program Files\Java\jdk1.6.0_22\bin;C:\Program Files\Java\jdk1.6.0_22\jre\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;e:\Program Files\vc6.0\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\SSH Communications Security\SSH Secure Shell;E:\db2\BIN;E:\db2\FUNCTION;E:\db2\SAMPLES\REPL;C:\PROGRA~1\BEASYS~1\TUXEDO\bin;C:\Program Files\Common Files\TTKN\Bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\Program Files\MySQL\MySQL Server 5.0\bin;E:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;E:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;E:\Program Files\Microsoft Visual Studio\Common\Tools;E:\Program Files\Microsoft Visual Studio\VC98\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;e:\Program Files\vc6.0\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\StormII\Codec;d:\Program Files\StormII
D:\>echo %CLASSPATH%
.;C:\Program Files\Java\jdk1.6.0_22\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_22\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_22\jre\lib\rt.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;E:\db2\java\db2java.zip;E:\db2\java\db2jcc.jar;E:\db2\java\db2jcc_license_cu.jar;E:\db2\bin;E:\db2\tools\db2XTrigger.jar;E:\db2\java\common.jar
E:\Java\book1>javac HelloWorld.java
E:\Java\book1>java HelloWorld
Hello Java world!
2、Tomcat
为什么Tomcat必须配置JAVA_HOME?
windows版本的jdk安装以后会将安装的路径写入系统的注册表里边的...很多程序不用配置JAVA_HOME是因为那些程序是直接通过读取注册表里边的路径获取了jdk的路径.比如eclipse; netbeans则是在安装的时候,安装程序会去注册表里边读取jdk的路径,直接把它写到netbeans的配置文件里边去了
而tomcat就没有这样去处理,只是简单地通过环境变量去获取jdk的路径,所以要运行tomcat一般都是要配置环境变量的..如果不配置也可以,修改tomcat/bin/startup.bat...tomcat这样做也是出于跨平台考虑的...因为系统注册表是只有windows系统才有的
为什么Tomcat的CATALINA_HOME不配置也可以?
在startup.bat的前一部分有下面的脚本代码
rem Guess CATALINA_HOME if not defined
set CURRENT_DIR=%cd%
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=%CURRENT_DIR%
同一台windows机器上安装多个TOMCAT
1.解压Tomcat到一个新的目录,E:\apache-tomcat-6.0.20;
2.新建一个环境变量CATALINA_HOME2,路径为E:\apache-tomcat-6.0.20;
3.编辑E:\apache-tomcat-6.0.20/bin/startup.bat和catalina.bat,把CATALINA_HOME全部替换成CATALINA_HOME2;
4.编辑E:\apache-tomcat-6.0.20/conf/server.xml,修改所有端口号;
可以直接在tomcat下创建web项目
例ch2
3、MySQL、JDBC
D:\Program Files\MySQL\MySQL Server 5.0
E:\MyEclipse\mysql-connector-java-5.1.17\mysql-connector-java-5.1.17-bin.jar
4、Ant
E:\apache-ant-1.8.2
系统环境变量:
Path:
c:\oracle\product\10.2.0\db_1\bin;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;e:\Program Files\vc6.0\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\SSH Communications Security\SSH Secure Shell;E:\db2\BIN;E:\db2\FUNCTION;E:\db2\SAMPLES\REPL;C:\PROGRA~1\BEASYS~1\TUXEDO\bin;C:\Program Files\Common Files\TTKN\Bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\Program Files\MySQL\MySQL Server 5.0\bin;E:\apache-ant-1.8.2------------zhj
ANT_HOME:
E:\apache-ant-1.8.2
C:\Documents and Settings\zhj\桌面>echo %Path%
c:\oracle\product\10.2.0\db_1\bin;C:\Program Files\Java\jdk1.6.0_22\bin;C:\Program Files\Java\jdk1.6.0_22\jre\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;e:\Program Files\vc6.0\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\SSH Communications Security\SSH Secure Shell;E:\db2\BIN;E:\db2\FUNCTION;E:\db2\SAMPLES\REPL;C:\PROGRA~1\BEASYS~1\TUXEDO\bin;C:\Program Files\Common Files\TTKN\Bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\Program Files\MySQL\MySQL Server 5.0\bin;E:\apache-ant-1.8.2\bin;E:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;E:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;E:\Program Files\Microsoft Visual Studio\Common\Tools;E:\Program Files\Microsoft Visual Studio\VC98\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;e:\Program Files\vc6.0\bin;C:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\SSH Communications Security\SSH Secure Shell;d:\Program Files\StormII\Codec;d:\Program Files\StormII
不重启电脑使修改得系统环境变量生效:
在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环境变量后,需重启系统才能使之生效。有没有什么方法可让它即时生效呢?下面介绍一种方法:
以修改环境变量“PATH”为例,修改完成后,进入DOS命令提示符,输入:set PATH=C: ,关闭DOS窗口。再次打开DOS窗口,输入:echo %PATH% ,可以发现“我的电脑”->“属性”->“高级”->“环境变量”中设置的 PATH 值已经生效。
不用担心DOS窗口中的修改会影响环境变量的值,DOS窗口中的环境变量只是Windows环境变量的一个副本而已。但是对副本的修改却会引发Windows环境变量的刷新,这正是我们想要的!
C:\Documents and Settings\zhj\桌面>ant
Buildfile: build.xml does not exist!
Build failed
D:\>mysql -uroot -pJunn9527
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
D:\>mysql -uroot -p123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
第3章 Eclipse入门
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决办法:
1、用mysql-connector-java-5.0.8-bin.jar或mysql-connector-java-5.1.17-bin.jar都可以,
我数据库为5.0.67-community-nt MySQL Community Edition (GPL);
2、把驱动放在E:\apache-tomcat-6.0.20\webapps\JavaWebStudy\WEB-INF\lib下就可以运行了;
3、在myclipse的Referenced libraries中导入后,发布时会自动把jar包复制到E:\apache-tomcat-6.0.20\webapps\JavaWebStudy\WEB-INF\lib下;
ANT
E:\Java\ant\Ech2>ant db
Buildfile: E:\Java\ant\Ech2\build.xml
BUILD FAILED
Error reading project file E:\Java\ant\Ech2\build.xml: Invalid byte 1 of 1-byte UTF-8 sequence.
Total time: 0 seconds
E:\Java\ant\Ech2>ant services-deploy
Buildfile: E:\Java\ant\Ech2\build.xml
BUILD FAILED
Error reading project file E:\Java\ant\Ech2\build.xml: Invalid byte 1 of 1-byte UTF-8 sequence.
Total time: 0 seconds
在Eclipse中集成ANT
Buildfile: E:\Java\book1\ant\Ech2\build.xml
BUILD FAILED
Error reading project file E:\Java\book1\ant\Ech2\build.xml: Invalid byte 1 of 1-byte UTF-8 sequence.
Total time: 125 milliseconds
阅读(2266) | 评论(0) | 转发(0) |