Servlet
来源:互联网 发布:新浪短网址api js 编辑:程序博客网 时间:2024/05/01 12:04
servlet生命周期: 类的加载,对象的产生,对象的使用,对象的销毁,类的卸载;初始化(GenericServlet):public void init() throws ServletException;服务,主要的两种服务的处理就是get与post没在HttpServle类里面有对象的方法定义: 处理get请求:protected void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException; 处理post请求:protected void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException; 销毁(GenericServlet):public void destory();post与get的区别: get:以实体的方式得到由请求URL所指定资源的信息; post:用来向服务器发出请求,要求他接受被附在请求后的实体;扩展生命周期:GenericServlet:public void init(ServletConfig config) throws ServletException;服务方法: GenericServlet:类:public abstract void service(ServleyRequest req,HttpServletResponse resp)throws ServletException,IOException; GenericServlet:类:protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException; 如果子类复写了service()方法。那么doGet,doPost方法无效;请问GenericServlet和HttpServlet有什么区别? GenericServlet属于HttpServlet的父类,本身不受协议控制,而HttpServlet只为http服务; HttpServlet中的service()方法负责分配用的请求的处理,以找到与之匹配的doXXX()方法;请问如果复写了HttpServlet类中的service()方法会怎么样? 所有的doGet()或者是doPost()方法都无法使用;jdbs属于门面设计模式内置对象的取得: PageContext不能够在Servlet中取得,因为PageContext属于jsp页面;取得Session对象: public HttpSession getSession() ;application往往会被getServletContext()方法所替代,实际上这个方法就可以通过Servley的父类取得, public ServletContext getServletContext(); ServletContext app = super.getServletContext();servlet跳转: 在整个WEB开发之中对于页面的跳转有两种形式: 客户端跳转:(页面改变,执行完跳转,不能专题request属性) 服务器跳转(页面不改变,立刻无条件跳转,可以传递request属性)servlet跳转到jsp(客户端跳转): response.sendRedirect("XXX.jsp");服务器端跳转: ·jsp标签:<jsp:forward page="xxx"> ·pageContext对象:pageContext.forward("");eg:request.getRequestDispatcher("/xxx.jsp").forward(request,rewsponse);EL语句:${param.msg}等价于request.getParameter("msg")EL缺陷:输出List集合过滤器: 过滤器初始化:public init(FilterConfig filterConfig) throws ServletException; FilterConfig可以取得初始化参数 执行过滤:public void doFilter(ServletRequest request,ServletResponse response,FilterChqain chain) throws IOException,ServletException; 销毁:public void destory();利用这个借口可以将当前的请求向后传递public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain);编码过滤:private String charset = "UTF-8";public void init(FilterConfig filterConfig) throws ServletException{ if(filterConfig.getInitParameter("charset")!=null){ this.charset=filterConfig.getInitParameter("charset"); }}配置文件的使用两种方式: java.util.Properties(HashTable的子类) java.util.ResourceBundle类处理,可以通过国际划处理
0 0
- Servlet
- servlet
- Servlet
- servlet
- Servlet
- servlet
- servlet
- Servlet
- Servlet
- servlet
- Servlet
- servlet
- servlet
- servlet
- Servlet
- servlet
- servlet
- servlet
- 魔术师发牌问题
- poj 3468 A Simple Problem with Integers
- 文件上传Upload
- $(window).load(function(){}) 和 $(document).ready(function(){})的区别
- cocos 动画 触摸事件
- Servlet
- Sequence小文件合并
- Java transient关键字使用小记
- 几个简单的博弈例子
- 【学习笔记】第八章 多态
- 文章标题
- Python 列表解析
- Eclipse 如何调整java和xml文件字体大小
- 对Memcached使用的总结和使用场景