Eclipse3.1.2 + Tomcat5.5.15 +Lomboz+XDoclet
安装 | 配置 (Jsp | Servlet | JavaBean)
一> I> Download SoftWare
Eclipse: http://www.eclipse.org/downloads/
(All in one) + Tomcatplugin + XDoclet-1.2.3;
(admin | compat | deployer | .) --- 解压到同一目录下.
Eclipse plugins: (安装: Copy | links)
Tomcatplugin: http://www.sysdeo.com/sysdeo/eclipse/tomcatplugin
Myeclipse: http://www.myeclipseide.com
(E3.1.2+emf-sdo-runtime.2.1.0 + lomboz.3.1Rc + XDoclet-1.2.3)
二> II> Deploy
Jdk: (SEV)
JAVA_HOME =jdk.path
CLASSPATH=.;%JAVA_HOME%/lib/dt.jar;
%JAVA_HOME%/lib/tool.jar;
PATH=%JAVA_HOME%/bin;
Tomcat: (SEV)
CATALINA_HOME=tomcat.path;
CATALINA_BASE =tomcat.path;
CLASSPATH: %CATALINA_HOME%/common/lib/servlet.jar;
建立自己的 webapp 目录:
a> 在webapps目录下新建一个目录,起名叫myapps;
b> myapps下新建一个目录WEB-INF, 注意大小写;
c> WEB-INF下新建一个文件web.xml,内容如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>My Web Application</display-name>
<description>
A application for test.
</description>
</web-app>
产生一下结构:
G:/TOMCAT/webapps/myapps/WEB-INF/classes 和 lib;
G:/TOMCAT/webapps/myapps下即可运行jsp!
{
建立非 webapps 下的目录: (
在 </host>前加上)
<Context path="/pp" docBase="myapps.path" debug="0"
reloadable="true" ></Context> Over!
}
完成第一个 servelet 程序:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
out.flush();
}
}
产生以下结构:
G:/TOMCAT/webapps/myapps/classes/test/Test.class
修改webapps/myapp/WEB-INF/web.xml,添加servlet和servlet-mapping 编辑后的web.xml如下所示,红色为添加的内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>My Web Application</display-name>
<description>
A application for test.
</description>
<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
</web-app>
<这一段声明了你要调用的Servlet,servlet-mapping则是将声明的servlet"映射"到地址/Test上>
建立自己的 Bean:
package test;
public class TestBean{
private String name = null;
public TestBean(String strName){
this.name=strName;
}
public void setName(String strName){
this.name=strName;
}
public String getName(){
return this.name;
}
}
产生以下结构:
G:/TOMCAT/webapps/myapps/classes/test/TestBean.class
新建一个 TestBean.jsp 文件:
<%@ page import="test.TestBean" %>
<html><body><center>
<%
TestBean testBean=new TestBean("This is a test java bean.");
%>
Java bean name is: <%=testBean.getName()%>
</center></body></html>
至此, Tomcat下的 Jsp | Servlet | JavaBean 的配置已经完成!