第一部,下载安装MyEclipse for mac.
http://downloads.myeclipseide.com/downloads/products/eworkbench/2014/installers/myeclipse-spring-2014-GA-offline-installer-macosx.dmg
http://downloads.myeclipseide.com/downloads/products/eworkbench/2014/installers/myeclipse-pro-2014-GA-offline-installer-macosx.dmg
第二部,helloWorld
1,新建项目
2, 新建MyServlet类,继承字HttpServlet,重写doGet和doPost方法,调用process方法响应请求。
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;
@SuppressWarnings("serial")
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
process(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
process(req,resp);
}
/**
* @param req
* @param resp
* @throws ServletException
* @throws IOException
*/
protected void process(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<HTML><HEAD><TITLE>My First Servlet</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>Hello , Jason Hu</H1>");
out.println("</BODY></HTML>");
}
}
3,在web.xml中配置servlet及servlet-mapping
4,执行项目,http://192.168.1.117:8080/HelloWorld/MyServlet5,项目代码包: 点击打开链接