黑马程序员技术交流社区

标题: 关于BaseServlet [打印本页]

作者: CanABirdFly?    时间: 2014-7-11 08:11
标题: 关于BaseServlet
包名省略

/**
* 一般Servlet都是只有一个请求方法
* 登录 一个 LoginServlet
* 注册一个RegistServlet
* 修改密码一个
*
* 我们需要一个Servlet有多个请求方法
*   login()
*   regist()
*   updatePassword()
*   
*   让你的Servlet去继承BaseServlet
*
* -----------
*
*   BaseServlet的特性
*   1.可有有多种请求处理方法
*   2 简化了转发重定向
*   
*   请求处理方法格式
*   pubilc String regist(HttpServletRequest request, HttpServletResponse response)
*       throws ServletException, IOException {
*   }
*   
*   请求BaseServlet中的某个方法
*   http://localhost:8080/tools/AServlet?method=regist
*   http://localhost:8080/tools/AServlet?method=login
* @author Phantom
*
*/
public class AServlet extends BaseServlet {
        public String regist(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                System.out.println("regist()...");
                return "/index.jsp";//转发到index.jsp
//                return "f:/index.jsp";//f前缀表示forward,即转发
//                return "r:/index.jsp";//r前缀表示redirect即 重定向
//                return null;//不转发也不重定向
//                return "";//不转发也不重定向

        }
       
        public String login(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                System.out.println("login()...");
                return "r:/index.jsp";
        }
}

作者: CanABirdFly?    时间: 2014-7-11 08:12
为自己点个赞,算不算水经验呢,这是我从我的博客里搞出来的
作者: CanABirdFly?    时间: 2014-7-11 08:46
再给自己顶一下
作者: battlexing    时间: 2017-10-23 00:14
没看懂





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2