编写第一个Servlet报错
package pack1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.GenericServlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.Date;
//@WebServlet("/hello")
public class test extends GenericServlet{
public void service(ServletRequest request,ServiceResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head><title>欢迎光临</title></head>");
out.println("<body>");
out.println("我的第一个Servlet源程序");
out.println("<br>");
out.println(new Date());
out.println("</body>");
out.println("</html>");
out.flush();
out.close();
}
@Override
public void service(ServletRequest arg0, ServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
public class HelloWorld extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
// 指定 HTTP 响应的输出的文档MIME类型,默认为text/html
// 常用的MIME类型还有image/gif(GIF图片)
// image/bitmap(BMP图象)
// text/plain(文本文档TXT)
// text/vnd.wap.wml(手机WAP页面)
// 同时可以指定了浏览器显示的编码, 如res.setContentType("text/html;charset=utf-8")
res.setContentType("text/html");
// getWriter() 方法用于得到一个输出流,来发送HTML标记
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World</h1>");
out.println("</body>");
out.println("</html>");
}
}