首先到sun的官方网站上下载jdk 1.5.
一路next ,安装完毕.
然后设置环境变量 path: D:\Program Files\Java\jdk1.5.0_05\bin
如下图: 
目前只设置一个path 就ok了,来我们来测试一下:
新建如下目录结构

在src目录下建立Hello.java 文件.
内容为

Code
package jack;
public class Hello
{
public static void main(String [] args)
{
System.out.println("test");
}
}
编译java文件

这时候 发现 classes 中出现java/hello.class
接着 执行

成功的输出test,而且 src下存放的是源代码,classes中存放的是 class文件,清晰明了,
在这补充说明下,为什么没有在这设置classpath呢???
一般 开发都在开始设置classpath:rt.jar (runtime),dt.jar.tools.jar
1.
rt.jar 默认就在 根classloader的加载路径里面 放在claspath是多此一举
不信你可以去掉classpath里面的rt.jar
然后用 java -verbose XXXX 的方式运行一个简单的类 就知道 JVM的系统根Loader的路径里面
不光rt.jar jre\lib下面的大部分jar 都在这个路径里
2.
tools.jar 是系统用来编译一个类的时候用到的 也就是javac的时候用到
javac XXX.java
实际上就是运行
java -Calsspath=%JAVA_HOME%\lib\tools.jar xx.xxx.Main XXX.java
javac就是对上面命令的封装 所以tools.jar 也不用加到classpath里面
3.
dt.jar是关于运行环境的类库,主要是swing的包 你要用到swing时最好加上
因此 可以不暂且不设置这些变量,如果设置别忘了添加一个.,表明当前路径.
..
现在我们来装tomcat6.0 很简单下载 zip包,然后解压变可,
双击start.bat ,什么一闪而过,什么也没有,太不给面子了吧
,原来 是没有设置java-home ,在环境变量中,设置
java-home:java的安装路径,在启动,
见图

端口 8080;
启动ie,输入http://localhost:8080/;回车
出现一个黄色的页面和好吃的大懒猫头像,那么恭喜你 ,tomcat 设置成功了~~~~
.
接着我们来配置servlet ,在tomcat的webapp目录下建文件夹myapp.在myaoo下建立如WEB_INF
文件夹,在WEB-INF中建立web.xml.
web.xml内容为

Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to myapp</display-name>
<description>
Welcome to myapp kalllx
</description>
</web-app>
同时在WEB_INF中建立classes 文件夹,classes中建立java文件,Test.java
test.java

Code
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Test extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>");
out.println("This is my first Servlet");
out.println("</title></head><body>");
out.println("<h1>Hello,World!</h1>");
out.println("</body></html>");
}
}
然后 cdm中编译,javac Test.java,如果提示什么httpservlet 没有找到是因为没有配置servlet的classpath 所以失败,
找到tomcat/lib/servletapi.jar,然后将他添加到classpath中 ,就ok了,注意我使用的tomcat是6,如果是5,这个jar在common中.
这下编译正常.
现在在web.xml中注册servlet .
web.xml

Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to myapp</display-name>
<description>
Welcome to myapp kalllx
</description>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
在ie中输入http://localhost:8080/myapp/HelloWorld
可以看到页面上显示了一个helloworld ,说明你成功了.
对于javabean ,我们同样在classes下建立一个java文件,名为TestBean.java
内容

Code
package test;
public class TestBean
{
private String name =null;
public TestBean(String nameInit){
this.name = nameInit;
}
public void setName(String newName){
this.name=newName;
}
public String getName(){
return this.name;
}
}
然后进行编译,
javabean不需要在web.xml中注册,现在建立一个jsp来调用javabean.
到myapp下建立一个jsp文件
testbean.jsp

Code
<%@ page import="test.TestBean" %>
<html>
<head>
<title>Test Bean</title>
</head>
<body>
<center>
<%
TestBean testBean = new TestBean("hdl");
%>
Java Bean Test:
the name of jack is <%=testBean.getName()%>
</center>
</body>
</html>
然后在ie中浏览 http://localhost:8080/myapp/testbean.jsp
如果没有出错的话,你会看到
Java Bean Test: the name of jack is hdl
一行文字`````.
ok servlet 与jsp的配置就介绍完了 ~~~
大家有空来小屋喝茶啊 