1)、 在官网上直接下载Eclipse IDE for Java EE Developers,解压即可;
【2】、 eclipse安装tomcat插件:
1)、 在http://www.eclipsetotale.com/tomcatPlugin.html上下载tomcatPluginV33.zip
2)、 解压到eclipse目录下的plugins目录中
3)、 重新启动eclipse
4)、下载Tomcat
5)、配置tomact的环境变量( CLASSPATH E:\Java\apache-tomcat-7.0.53\lib\servlet-api.jar)
6)、 在Window -> Prefences -> Tomcat配置tomcat。Tomcat home 选择刚才下载Tomcat的目录7)、 点击start tomcat按钮,可以发现大量打印信息,在浏览器中输入http://localhost:8080,出现tomcat的网页,证明已经安装好了。
【3】、 新建Servlet测试程序
1)、 选择菜单File->New->Project... ,在新建项目向导中选择 Web->Dynamic Web Project,project name为MyFirstDynamicWebProject,一路next,最后选择生成web.xml;
2)、 new 一个class,package com.johnny.test,name为helloworld,super class 为HttpServlet;3)、 code:
- package com.majia.test;
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class HelloWorld extends HttpServlet implements javax.servlet.Servlet{
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#HttpServlet()
- */
- public HelloWorld() {
- super();
- }
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
- HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.getWriter().write("Hello, world 1112!");
- }
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
- HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- // TODO Auto-generated method stub
- }
- }
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
- <servlet>
- <servlet-name>HelloWorld</servlet-name>
- <servlet-class>com.johnny.test.HelloWorld</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>HelloWorld</servlet-name>
- <url-pattern>/helloworld</url-pattern>
- </servlet-mapping>
- </web-app>
4)、 右键点击HelloWorld.java,选择rus as :run on server,在浏览器上会显示:Hello, world 1112!