标签:
HttpServlet抽象类:为处理http请求的servlet提供了一般实现,主要是定义和实现了若干service方法。
package linkin; 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; public class LinkinServlet implements Servlet { public void destroy() { System.out.println("销毁的方法被调用。。。"); } public ServletConfig getServletConfig() { return null; } public String getServletInfo() { return null; } public void init(ServletConfig arg0) throws ServletException { System.out.println("初始化方法被调用。。。"); } public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { //1.编写输出语句,证明当前方法被调用 System.out.println("处理请求,返回响应。。。"); //2.通过PrintWriter对象向浏览器端发送响应信息 PrintWriter writer = arg1.getWriter(); writer.write("成功跳转。。。"); writer.close(); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>LinkinServlet</servlet-name> <!-- 注册Servlet实现类的全类名 --> <servlet-class>linkin.LinkinServlet</servlet-class> </servlet> <!-- 建立一个从虚拟路径到Servlet组件之间的映射关系 --> <servlet-mapping> <!-- 引用Servlet组件名称 --> <servlet-name>LinkinServlet</servlet-name> <!-- 映射到Servlet的虚拟路径:“/LinkinServlet” --> <url-pattern>/LinkinServlet</url-pattern> </servlet-mapping> </web-app>
标签:
原文地址:http://blog.csdn.net/u011794238/article/details/46495019