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 ServletText extends HttpServlet {
public ServletText() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void init() throws ServletException {
}
}
这是我第一次用Eclipse+MyEclipse+tomcat生成的 Servlet 代码
创建了个 web-project工程(WebProject)
新建了个 servlet
在 myEclipse 中启动 tomcat 后, 输入 http://localhost:8080/WebProject/ServletText
页面显示
type Status report
message /WebProject/Servlet
description The requested resource (/WebProject/Servlet) is not available.
随后创建一个 JSP 后, 输入http://localhost:8080/WebProject/MyJsp.jsp 可以访问
请问 Servlet 是不是要 先进行编译 了才可以进行访问呢? (我不会编译)
若需要编译,那在 Eclipse+MyEclipse下如何编译呀?
编译后再怎么访问Servlet呢?