import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
//实现Servlet接口来开发Servlet程序
public class Demo3 implements Servlet {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}
@Override
public void init(ServletConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
//取得服务端向浏览器的输出流对象
PrintWriter pw = response.getWriter();
pw.write("welcome to java web coure!");
}
}
web.xml
<servlet>
<servlet-name>Demo3</servlet-name>
<servlet-class>cn.web.http.Demo3</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Demo3</servlet-name>
<url-pattern>/Demo3</url-pattern>
</servlet-mapping>
原文地址:http://blog.51cto.com/357712148/2104355