• 12 Servlet_04 Servlet增删改查 静态页面与动态页面 EL表达式 table表格的一些样式


    今天学习了servlet的增删改查:

    存储数据
    setAttribute(String name,Object obj );
    获取数据
    getAttribute(String name);
    删除数据
    removeAttribute(String name);

    servlet小知识点:

    req  请求

    resp 反馈

    Servlet request域(只能使用一次)

    Servlet Context域(能够长时间使用,随服务器关闭而关闭)

    静态页面与动态页面:

    html 页面被称为静态页面 页面内容基本上是不变的

    jsp;php 动态页面 (根据不同的情况显示不同的内容,经常会随着后端服务器需求的变化而变化)
    在jsp页面上,需要动态接收后端服务器传输给前段jsp界面的数据
    通过EL表达式来实现动态的接收服务器传输的数据 Expression Language
    request域和ServletContext域中的值是可以传输到页面中的

    EL表达式:

    EL表达式的语法: 遵从key-value键值对这种数据结构
    通过key获取value值
    ${key} key指的就是放进域中的name名称值
    EL表达式只能在jsp动态页面中使用(欢迎界面可以),对于html页面不支持

    table 表格:

    单元格与单元格之间的间距 外边距 cellSpacing
    单元格边框与单元格内容之间的间距 内间距 cellpadding
    合并table表格内部边框线 border-collapse:collapse(合并)
    合并一列中的多行 rowspan
    合并一行中的多列 colspan

    水平对齐方式 align let center rigdt
    垂直对齐方式 valid top middle bottom
    表格的背景颜色 blackground-color
    表格边框宽度 border
    表格的标题 caption
    文本内容居中 text-aline : center

    Servlet例题格式:

    正常流程:  

    @WebServlet("/getData01")(映射)
    //从tomcat服务器中取出全局域对象
            ServletContext context = req.getServletContext();
            //从全局域对象中取出用户名和密码值
            if (context.getAttribute("username") != null && context.getAttribute("password") != null) {
    
                String username = context.getAttribute("username").toString();//null被引用了  触发了空指针
                String password = context.getAttribute("password").toString();
    
                System.out.println("getData01" + username + "---");
                System.out.println("getData01" + password + "---");
    
            } else {
                //  表明该ServletContext域中没有此用户信息  该返回首页
                resp.sendRedirect("/index.jsp");
               // System.exit(0);  破坏性行为  直接停止虚拟机(所有程序停止)
                return;//返回  让当前正在执行的方法结束掉
    
            }
            //资源跳转   getData02
            resp.sendRedirect("/getData02");



    @WebServlet("/getData02")(映射)
     //从服务器中获取ServletContext对象
    ServletContext context = req.getServletContext();
    //从ServletContext域对象中取出用户名和密码值
    String username = context.getAttribute("username").toString();
    String password = context.getAttribute("password").toString();
    System.out.println(username+"+++++");
    System.out.println(password+"+++++");
    // 资源跳转 removeData01
    resp.sendRedirect("/removeData01");


  • 相关阅读:
    spring cloud/spring boot同时支持http和https访问
    解决to the cache because there was insufficient free space available after evict
    国外天气api 国际天气预报今天、未来3天、未来7天的天气预报信息接口
    java 访问get接口请求外部的json数据
    IDEA创建基于Maven的SpringBoot项目-多模块
    PostgreSQL提取每个ID的最后一行(Postgresql extract last row for each id)
    Vue项目引入百度地图
    Vue 引入天地图 & 地图类型切换
    js在新窗口打开链接
    mysql使用小数注意
  • 原文地址:https://www.cnblogs.com/rxqq/p/13886737.html
Copyright © 2020-2023  润新知