编程开发 > JAVA > 文章内容

java基础知识总结(170)

2016-9-27编辑:ljnbset

servlet知识点小结

        一、servlet基础

                 1、什么是servlet?

                 2、如何开发一个servlet?

                 3、什么是servlet容器?

                 4、了解http协议

        二、servlet核心

                 1、servlet核心类与接口

                           a,Servlet接口

                           b,GenericServlet抽象类

                         c,ServletConfig接口

                                    String getInitParameter(String paraName);

                                    ServletContext getServletContext();

                           d,HttpServlet抽象类

                           e,HttpServletRequest接口(ServletRequest)

                                    String getParameter(String paraName);

                                    String[] getParameterValues(String paraName);

                                    setCharacterEncoding(String code);

                                    String getRequestURI();

                                    setAttribute(String name,Object obj);

                                    Object getAttribute(String name);

                                    removeAttribute(String name);

                                    RequestDispatcher getRequestDispatcher(String url);

                                    Cookie[] getCookies();

                                    String getContextPath();

                                    getRemoteAddr();

                           f,HttpServletResponse接口(ServletResponse)

                                    setContentType(String type);

                                    PrintWriter getWriter();

                                    sendRedirect(String url);

                                    addCookie(Cookie cookie);

                                    encodeURL(String url);

                                    encodeRedirectURL(String url);

                           g, ServletContext接口

                                    setAttribute(String name,Object obj);

                                    Object getAttribute(String name);

                                    removeAttribute(String name);

                                    String getRealPath(String url);

                                    String getInitParameter(String paraName);

                 2、servlet的生命周期

                           1)servlet的生命周期分成哪几个阶段?

                           2)如何override init方法。

                           3)load-on-starup参数

                           4)如何配置初始化参数(init-param)

                 3、表单处理

                           1)如何获得表单的参数?

                           2)如何获取表单的中文参数值?

                 4、get方式与post方式

                           1)哪一些请求是get请求方式

                           2)哪一些请求是post请求方式

                           3)二者的区别

                 5、转发与重定向

                           1)什么是转发?

                           2)如何转发?以及要注意的问题?

                           3)转发的特点?

                           4)什么是重定向?

                           5)如何重定向?以及要注意的问题?

                           6)重定向的特点?

                           7)二者的区别?

        三、状态管理

                           1) 什么是状态管理?

                           2) cookie技术

                                    a,什么是cookie?

                                    b,cookie如何创建?

                                             Cookie c = new Cookie("username","abc");

                                             response.addCookie(c);

                                    c,cookie的编码问题?

                                             String URLEncoder.encode(String name,String code);

                                             String URLDecoder.decode(String name,String code);

                                    d,cookie的查询

                                             Cookie[] request.getCookies();

                                             String cookie.getName();

                                             String cookie.getValue();

                                    f,cookie的生存时间

                                              cookie.setMaxAge(int seconds)

                                    g,cookie的路径问题

                                              cookie.setPath(String path)

                                    h,cookie的限制

                           3) session技术

                                    a, 什么是session?

                                    b, 如何获得session?

                                             HttpSession request.getSession();

                                             HttpSession request.getSession(boolean flag);

                                    c,session的常用方法

                                             setAttribute(String name,Object obj);

                                             Object getAttribute(String name);

                                             removeAttribute(String name);

                                             String getId();

                                    d, session的超时

                                             setMaxInactiveInterval(int seconds)

                                    e,删除

                                             invalidate();

                                    g,用户禁止cookie以后,如何继续使用session?

                                             使用url重写

        四、数据库访问

                           1、使用jdbc访问数据库

                           2、dao

                                    a,什么是dao?

                                    b,如何写一个dao?

         五、过滤器与监听器

                            1、什么是过滤器?

                            2、如何写一个过滤器?

                            3、过滤器初始化参数?

                            4、优先级

                            5、什么是监听器?

                            6、如何写一个监听器?

        六、案例

                           1、session验证

                           2、验证码

                           3、购物车

                           4、员工的增删改查

       

        练习:

                           “交友平台"

                 功能:

                           1、注册

                                    a,将用户注册信息插入数据库

                                    b,验证码

                                    c,用户名要求唯一

                           2、登录

                                    a,验证用户名和密码

                           3、用户列表

                                    a,显示所有已注册用户的信息(除了真实姓名与

                                    电话)

                                    b,点击“详细"链接, 会跳转到“用户详细信息列表"

                           4、用户详细信息列表

                                    a,列出用户的真实姓名和电话

                                    b, 如果是当前用户(比如,sdd登录了该系统,

                                    并且,点击的也是sdd用户的“详细”链接),

                                    则可以上传照片。

                                    c, 查看照片(会显示该用户的所有照片)。

                                    d, 如果用户没有登录,则看不到照片,也

                                    不能上传照片。

                                   

                 实现:

                           1、注册

                                    a, 创建一个表t_frienduser:

                                    create table t_frienduser(

                                             id int primary key auto_increment,

                                             username varchar(50) unique,

                                             name varchar(100),

                                             pwd varchar(20),

                                             age int,

                                             gender char(1),

                                             phone varchar(20)

                                    );

                                    create table t_friendpic(

                                             id int primary key auto_increment,

                                             picName varchar(50),

                                             userId int

                                    );

                                    使用用户的id来创建一个文件夹,用于

                           存放照片文件。

                                    比如 建一个文件夹 pic_1

                           2、登录

                           3、用户列表

                           4、用户详细信息列表

                                    b,只需要比较session中保存的用户的id

                           与点击“详细”链接时的id,如果相等,则是

                           当前用户,显示上传文件。

                                    c,通过用户的id,查询t_friendpic表,获得

                                    照片文件的名称。

                                    d,上传文件时,要将文件保存到pic_id文件

                                    夹,并且要文件名保存到t_friendpic表。

java基础知识总结(169)

热点推荐

登录注册
触屏版电脑版网站地图