实现Servlet接口来开发Servlet程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现Servlet接口来开发Servlet程序相关的知识,希望对你有一定的参考价值。
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>
以上是关于实现Servlet接口来开发Servlet程序的主要内容,如果未能解决你的问题,请参考以下文章