javaweb编程从⼊门到实践pdf_《JavaWeb编程从⼊门到实
践》读书笔记(⼀)
第1篇 Java Web开发基础篇
第1章 Java Web开发概述
1、Java语⾔
Jsp和技术都是⽤Java语⾔实现的,Java组件都是⽤Java开发的;
2、Java Web
B/S模式;
使⽤HTTP协议;
服务器把数据组织成HTML格式;
Web服务器:Tomcat,IBM ,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
java和jspStudio\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\db2X
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/at这样做也是出于跨平台考虑的...因为系统注册表是只有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/l,修改所有端⼝号;
可以直接在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:\WI 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 Fil
es\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: l 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: sql.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\l
BUILD FAILED
Error reading project file E:\Java\ant\l: Invalid byte 1 of 1-byte UTF-8 sequence.
Total time: 0 seconds
E:\Java\ant\Ech2>ant services-deploy
Buildfile: E:\Java\ant\l
BUILD FAILED
Error reading project file E:\Java\ant\l: Invalid byte 1 of 1-byte UTF-8 sequence.
Total time: 0 seconds
在Eclipse中集成ANT
Buildfile: E:\Java\book1\ant\l
BUILD FAILED
Error reading project file E:\Java\book1\ant\l: Invalid byte 1 of 1-byte UTF-8 sequence. Total time: 125 milliseconds
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论