搭建eclipse servlet环境

下载Eclipse

http://www.eclipse.org/

 

下载Tomcat Eclipse插件

http://www.eclipsetotale.com/tomcatPlugin.html

将tomcatPluginV321.zip内容解压到 Eclipse 的 plugins 目录,然后重启Eclipse

Window->Perferences->Tomcat 配置好版本目录等熟悉,记得按Apply

 

下载Tomcat

http://tomcat.apache.org/

 

测试servlet例子

File->New->New Project(java Tomcat Project)

输入 test next 再输入 test 最后finish

右键test工程,new class 包名test,类名test 

超类的名称写上javax.servlet.http.HttpServlet

 

打开test.java ,右键test.java文件内容 source->Override/Implement Methods

选上 doGet doPost

去掉基类调用super.doGet(req, resp);

输入

PrintWriter out = new PrintWriter (resp.getOutputStream()); out.println("<html>"); out.println("<head><title>Servlet1</title></head>"); out.println("<body>hello world!"); out.println("</body></html>"); out.close();   

右击PrintWriter,source->Organize Import

然后右击test工程,选择Properties->java build path->order and export 全选然确定

 

创建该工程的部署文件web.xml  放到test/Web-INF目录下

<?xml version="1.0" encoding="ISO-8859-1"?> <web-app> <servlet> <servlet-name>test</servlet-name> <servlet-class>test.test</servlet-class> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/test/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> </web-app>   

启动tomcat

访问 http://localhost:8080/test/test

你可能感兴趣的:(eclipse,tomcat,servlet,eclipse插件,plugins,encoding)