other选项,在Tomcat上打勾,好了,看到小猫的图标没有。
9. 试下Start Tomcat按钮,好了,Tomcat在console中启动了。
例子:
下面做个Hello World的例子
1. 选择File->New->Project
2. 在对话框中选择Tomcat Project,然后next
3. 输入Project Name,这里可以写HelloWorld,继续next
4. 勾上can update server.xml file选项,finish,好了,一个Poject已经创建好了。
5. 打开new class 向导,在Name中填入HelloWorld,在Superclass中填入javax.servlet.http.HttpServlet,按下 finish,好了,一个servlet就创建好了
6. 在HelloWorld.java中重载doGet方法,代码如下:
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("Hello World!");
}
}
8.Ctrl+S保存,右键HelloWorld project,选择Tomcat Project->update context to server.xml
7.在Eclipse中启动Tomcat
9.在用浏览器访问http://localhost:8080/HelloWorld/servlet/HelloWorld
10.怎么样,看到HelloWorld了没有