jsp原理与EL,JSTL表达式基础内容整理

2024年了,vue都到了灌篮高手的版本,真的没想到我还会在这个时间整理一篇关于jsp页面操作的文章。技术就是一个不用就忘的东西,既然工作中还有用武之地,那就整理一下以备不时之需。

长话短说,不展开叙述,只记录关键点,回头看起来可以由点带面的回顾。

一、jsp页面与servlet

首先JSP 本质上就是一个 Servlet

JSP 在被访问时,由JSP容器(Tomcat)自动将其转换为 Java文件(Servlet),在由JSP容器(Tomcat)将其编译,最终对外提供服务的其实就是这个字节码文件,以下是我在本地项目中随便找了一个jsp页面转换成的字节码文件:

/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.54
 * Generated at: 2022-04-25 08:21:27 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.WEB_002dINF.pages.manage;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class login_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
 ConfigView configView = ConfigView.getInstance(); 
      out.write('\r');
      out.write('\n');

    String path = request.getContextPath();
    String base = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

      out.write("\r\n");
      out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n");
      out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n");
      out.write("<head>\r\n");
      out.write("    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"  />\r\n");
      out.write("    <title>");
      out.print(configView.getSystemname_admin() );
      out.write("</title>\r\n");
      out.write("    <style>\r\n");
      out.write("        ul, li, ol {\r\n");
      out.write("            list-style: none\r\n");
      out.write("        }\r\n");
      out.write("        .box_center{\r\n");
      out.write("            margin-top: 10px;\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("        }\r\n");
      out.write("        .clearfix {\r\n");
      out.write("            clear: both;\r\n");
      out.write("        }\r\n");
      out.write("        .box_center .pagination{\r\n");
      out.write("            width:300px;\r\n");
      out.write("            height: 100%;\r\n");
      out.write("            display: -webkit-box; /* Chrome 4+, Safari 3.1, iOS Safari 3.2+ */\r\n");
      out.write("            display: -moz-box; /* Firefox 17- */\r\n");
      out.write("            display: -webkit-flex; /* Chrome 21+, Safari 6.1+, iOS Safari 7+, Opera 15/16 */\r\n");
      out.write("            display: -moz-flex; /* Firefox 18+ */\r\n");
      out.write("            display: -ms-flexbox; /* IE 10 */\r\n");
      out.write("            display: flex; /* Chrome 29+, Firefox 22+, IE 11+, Opera ;
      out.write("            font-size: 20px;\r\n");
      out.write("            text-align: center;\r\n");
      out.write("            width: 215px;\r\n");
      out.write("            height: 58px;\r\n");
      out.write("            line-height: 58px;\r\n");
      out.write("            color: #939aac;\r\n");
      out.write("            border-radius: 5px;\r\n");
      out.write("            cursor: pointer;\r\n");
      out.write("        }\r\n");
      out.write("        .box_center .pagination .selected{\r\n");
      out.write("            color: #fff;\r\n");
      out.write("            background: #4f77fc;\r\n");
      out.write("        }\r\n");
      out.write("    </style>\r\n");
      out.write("    <link href=\"");
      out.print(request.getContextPath() );
      out.write("/css/style_ty.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n");
      out.write("    <link rel=\"stylesheet\" type=\"text/css\" href=\"");
      out.print(request.getContextPath());
      out.write("/js/skins/chrome.css\"/>\r\n");
      out.write("    ");
      out.write("/js/Validform/Validform_v5.3.2.js\"></script>\r\n");
      out.write("    <script type=\"text/javascript\" src=\"");
      out.print(request.getContextPath());
      out.write("/js/zpks.js\"></script>\r\n");
      out.write("    <script type=\"text/javascript\">\r\n");
      out.write("        var browser=navigator.appName;\r\n");
      out.write("        var b_version=navigator.appVersion;\r\n");
      out.write("        var version=b_version.split(\";\");\r\n");
      out.write("        if(version!=null&&version.length > 1){\r\n");
      out.write("            var trim_Version=version[1].replace(/[ ]/g,\"\");\r\n");
      out.write("            if(browser==\"Microsoft Internet Explorer\" && trim_Version==\"MSIE7.0\")\r\n");
      out.write("            {    alert(\"您的浏览器版本过低,请选择IE8及以上版本\");\r\n");
      out.write("                window.opener=null;\r\n");
      out.write("                window.open(\"\",\"_self\");\r\n");
      out.write("                window.close();\r\n");
      out.write("            }\r\n");
      out.write("            else if(browser==\"Microsoft Internet Explorer\" && trim_Version==\"MSIE6.0\"){\r\n");
      out.write("                alert(\"您的浏览器版本过低,请选择IE8及以上版本\");\r\n");
      out.write("                window.opener=null;\r\n");
      out.write("                window.open(\"\",\"_self\");\r\n");
      out.write("                window.close();\r\n");
      out.write("            }\r\n");
      out.write("        }\r\n");
      out.write("\r\n");
      out.write("        jQuery(document).ready(function() {\r\n");
      out.write("            var msg = '");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${requestScope.msg}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("';\r\n");
      out.write("            var flag = '");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${requestScope.icon}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("';\r\n");
      out.write("            var icon;\r\n");
      out.write("            if(flag=='1'){\r\n");
      out.write("            \ticon='succeed';\r\n");
      out.write("            }else{\r\n");
      out.write("            \ticon='error';\r\n");
      out.write("            }\r\n");
      out.write("            if(msg!=null&&msg!=\"\"){\r\n");
      out.write("                art.dialog({\r\n");
      out.write("                    title:'提示 ',\r\n");
      out.write("                    content:msg,\r\n");
      out.write("                    icon:icon,\r\n");
      out.write("                    lock:true,\r\n");
      out.write("                    resize:false\r\n");
      out.write("                });\r\n");
      out.write("            }\r\n");
      out.write("        });\r\n");
      out.write("\r\n");
      out.write("        function trim(str){ //删除左右两端的空格\r\n");
      out.write("            return str.replace(/(^\\s*)|(\\s*$)/g, \"\");\r\n");
      out.write("        }\r\n");
      out.write("\r\n");
      out.write("        function loginxt(param){\r\n");
      out.write("            if(param == 1){\r\n");
      out.write("                var yusername = document.getElementById(\"yusername\").value;\r\n");
      out.write("                var ypasswd = 
      out.write("                }\r\n");
      out.write("                if(ypasswd==null||ypasswd==\"\"){\r\n");
      out.write("                    art.dialog({\r\n");
      out.write("                        title:'提示 ',\r\n");
      out.write("                        content:'密码不能为空!',\r\n");
      out.write("                        icon:'warning',\r\n");
      out.write("                        lock:true,\r\n");
      out.write("                        resize:false\r\n");
      out.write("                    });\r\n");
      out.write("                    return;\r\n");
      out.write("                }\r\n");
      out.write("   /*             if(key==null||key==\"\"){\r\n");
      out.write("                    art.dialog({\r\n");
      out.write("                        title:'提示 ',\r\n");
      out.write("                        content:'短信验证码不能为空!',\r\n");
      out.write("                        icon:'warning',\r\n");
      out.write("                        lock:true,\r\n");
      out.write("                        resize:false\r\n");
      out.write("                    });\r\n");
      out.write("                    return ;\r\n");
      out.write("                }*/\r\n");
      out.write("                document.getElementById(\"username\").value=strEncode(trim(yusername));\r\n");
      out.write("                document.getElementById(\"passwd\").value=strEncode(trim(ypasswd));\r\n");
      out.write("                document.getElementById(\"yusername\").value=\"\";\r\n");
      out.write("                document.getElementById(\"ypasswd\").value=\"\";\r\n");
      out.write("                document.getElementById(\"loginformdw\").action=\"");
      out.print(path);
      out.write("/login/saveLogin.htm\";\r\n");
      out.write("                document.getElementById(\"loginformdw\").submit();\r\n");
      out.write("            }else if(param ==2){\r\n");
      out.write("                document.getElementById(\"loginformjg\").action=\"");
      out.print(path);
      out.write("/login/saveLogin.htm\";\r\n");
      out.write("                document.getElementById(\"loginformjg\").submit();\r\n");
      out.write("            }\r\n");
      out.write("\r\n");
      out.write("        }\r\n");
      out.write("    </script>\r\n");
      out.write("    <script type=\"text/javascript\">\r\n");
      out.write("        var InterValObj;\r\n");
      out.write("        var count = 120;\r\n");
      out.write("        var curCount;\r\n");
      out.write("        function sendMessage() {\r\n");
      out.write("            }\r\n");
      out.write("            if(passwd==\"\"||passwd==null){\r\n");
      out.write("                alert(\"请填写密码\");\r\n");
      out.write("                return;\r\n");
      out.write("            }\r\n");
      out.write("            username = strEncode(trim(username));\r\n");
      out.write("            passwd = strEncode(trim(passwd));\r\n");
      out.write("            $.post(\"");
      out.print(request.getContextPath());
      out.write("/login/validateNumByUser.htm\",{\"username\":username,\"passwd\":passwd,\"ts\":Math.random()}, function(data){\r\n");
      out.write("                if(data==\"0\"){\r\n");
      out.write("                    alert(\"用户不存在!\");\r\n");
      out.write("                }else if(data==\"1\"){\r\n");
      out.write("                    alert(\"输入密码不正确!\");\r\n");
      out.write("                }else if(data==\"2\"){\r\n");
      out.write("                    alert(\"服务器繁忙,请稍后!\");\r\n");
      out.write("                }else if(data==\"4\"){\r\n");
      out.write("                    alert(\"距离您前一个短信发送没超过24小时,请用之前短信验证码登录!\");\r\n");
      out.write("                }else if(data==\"6\"){\r\n");
      out.write("                    alert(\"还未绑定手机号请通过首次登录绑定手机号!\");\r\n");
      out.write("                }else{\r\n");
      out.write("                    curCount = count;\r\n");
      out.write("                    $(\"#btn\").attr(\"disabled\", \"disabled\");\r\n");
      out.write("                    $(\"#btn\").val(\"重新获取\" + curCount + \"秒\");\r\n");
      out.write("                    InterValObj = window.setInterval(SetRemainTime, 1000);\r\n");
      out.write("                }\r\n");
      out.write("            });\r\n");
      out.write("        }\r\n");
      out.write("        function SetRemainTime() {\r\n");
      out.write("            if (curCount == 0) {\r\n");
      out.write("                window.clearInterval(InterValObj);//停止计时器\r\n");
      out.write("                $(\"#btn\").removeAttr(\"disabled\");//启用按钮\r\n");
      out.write("                $(\"#btn\").val(\"获取短信验证码\");\r\n");
      out.write("            }else {\r\n");
      out.write("                curCount--;\r\n");
      out.write("                $(\"#btn\").val(\"重新获取\" + curCount + \"秒\");\r\n");
      out.write("            }\r\n");
      out.write("        }\r\n");
      out.write("    </script>\r\n");
      out.write("</head>\r\n");
      out.write("<body class=\"lg_di\">\r\n");
      out.write("<div class=\"centbg\">\r\n");
      out.write("    <div class=\"container\">\r\n");
      out.write("        <div class=\"admin_title margint50\">");
      out.print(configView.getSystemname_admin() );
      out.write("</div>\r\n");
      out.write("\r\n");
      out.write("        <div class=\"login_panel\">\r\n");
      out.write("            <div class=\"box_center\">\r\n");
      out.write("                <ul class=\"pagination\">\r\n");
      out.write("                    <li class=\"selected\">首次登录</li>\r\n");
      out.write("                    <li>正常登录</li>\r\n");
      out.write("                </ul>\r\n");
      out.write("            </div>\r\n");
      out.write("            <ul id=\"contents\">\r\n");
      out.write("                <li class=\"show\">\r\n");
      out.write("                    <form  action=\"");
      out.print(path);
      out.write("/login/saveLoginFirst.htm\" method=\"post\" id=\"loginformdwf\" autocomplete=\"off\">\r\n");
      out.write("                        <input  type=\"hidden\" name = \"usernamef\" id = \"usernamef\" />\r\n");
      out.write("                        <input  type=\"hidden\" name = \"passwdf\" id = \"passwdf\" />\r\n");
      out.write("                        <input  type=\"hidden\" name = \"newpasswdf\" id = \"newpasswdf\" />\r\n");
      out.write("                        <input  type=\"hidden\" name = \"phonef\" id = \"phonef\" />\r\n");
      out.write("                        <div id=\"con_one_1\" style=\"display: block;\">\r\n");
      out.write("                            <div id=\"logintab-content1\" class=\"block\"> <font class=\"fontdl\">首次登录</font>\r\n");
      out.write("                                <p>\r\n");
      out.write("                                    <font class=\"fontstyle\">登录名:</font>\r\n");
      out.write("                                    <input   name=\"yusernamef\" id =\"yusernamef\"  value=\"登录名\"  class=\"loginbgn\" type=\"text\"  onfocus=\"if(this.value==defaultValue) {this.value='';this.style.color='#000';}\" onblur=\"if(!value){value=defaultValue;this.style.color='#999'}\" style=\"color:#999\"/>\r\n");
      out.write("                                </p>\r\n");
      out.write("                                <p>\r\n");
      out.write("                                    <input type=\"password\"  class=\"loginbgp\"  id=\"passwdbnyf\" style=\"display: none\"; />\r\n");
      out.write("                                    <font class=\"fontstyle\">密码:</font>\r\n");
autocomplete=\"off\" />\r\n");
      out.write("                                </p>\r\n");
      out.write("                                <p> <font class=\"fontstyle\"> 短信验证码:</font>\r\n");
      out.write("                                    <input name=\"keyf\" id = \"keyf\" type=\"text\" value=\"手机短信验证码\" onfocus=\"if(this.value==defaultValue) {this.value='';this.style.color='#000';}\" onblur=\"if(!value){value=defaultValue;this.style.color='#999'}\" style=\"color:#999; width:160px; padding-left:10px;\" />\r\n");
      out.write("                                    <input class=\"btnsms\" style=\"width:130px; padding-left:5px; background-color:#eaeced; border:1px solid #b0dfef;\" type=\"button\" name=\"btn\" id=\"btnf\" value=\"获取短信校验码\" onclick=\"sendMessagef()\"/>\r\n");
      out.write("                                </p>\r\n");
      out.write("                                <div class=\"divlg\"> <a class=\"login_bt\" href=\"#\" target=\"_self\"  onclick=\"loginxtf()\">登录</a>  </div>\r\n");
      out.write("                                <input type=\"hidden\" id=\"msgf\" value=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${requestScope.msg }", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("\"/>\r\n");
      out.write("                            </div>\r\n");
      out.write("                        </div>\r\n");
      out.write("                    </form>\r\n");
      out.write("\r\n");
      out.write("                </li>\r\n");
      out.write("                <li>\r\n");
      out.write("                    <form  action=\"");
      out.print(path);
      out.write("/login/saveLogin.htm\" method=\"post\" id=\"loginformdw\" autocomplete=\"off\">\r\n");
      out.write("                        <input  type=\"hidden\" name = \"username\" id = \"username\" />\r\n");
      out.write("                        <input  type=\"hidden\" name = \"passwd\" id = \"passwd\" />\r\n");
      out.write("\r\n");
      out.write("                        <div id=\"logintab-content2\" class=\"block\"> <font class=\"fontdl\">正常登录</font>\r\n");
      out.write("                            <p>\r\n");
      out.write("                                <input name=\"logintype\" id =\"longintype\"  value=\"dw\"  type=\"hidden\"/>\r\n");
      out.write("                                <font class=\"fontstyle\">登录名:</font>\r\n");
      out.write("                                <input   name=\"yusername\" idr=\"if(!value){value=defaultValue;this.style.color='#999'}\" style=\"color:#999\" /></p>\r\n");
      out.write("                -->\r\n");
      out.write("                                <input type=\"password\"  class=\"loginbgp\"  id=\"passwdbny\" style=\"display: none\"; />\r\n");
      out.write("                                <font class=\"fontstyle\">密码:</font>\r\n");
      out.write("                                <input type=\"text\"  name=\"ypasswd\"    id=\"ypasswd\" class=\"loginbgp\" placeholder=\"请输入密码\" autocomplete=\"off\" onfocus=\"this.type='password'\" />\r\n");
      out.write("                            </p>\r\n");
      out.write("                            <p> <font class=\"fontstyle\"> 短信验证码:</font>\r\n");
      out.write("                                <input name=\"key\" id = \"key\"
      out.write("                            <div class=\"divlg\"> <a class=\"login_bt\" href=\"#\" target=\"_self\"  onclick=\"loginxt(1)\">登录</a> <a class=\"login_bt_qx\" href=\"#\" target=\"_self\">取消</a> </div>\r\n");
      out.write("                            <input type=\"hidden\" id=\"msg\" value=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${requestScope.msg }", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("\"/>\r\n");
      out.write("                            <input type=\"hidden\" id=\"icon\" value=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${requestScope.icon }", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null, false));
      out.write("\"/>\r\n");
      out.write("                        </div>\r\n");
      out.write("\r\n");
      out.write("                    </form>\r\n");
      out.write("\r\n");
      out.write("                </li>\r\n");
      out.write("        var username=document.getElementById(\"yusernamef\").value;\r\n");
      out.write("        var passwd=document.getElementById(\"ypasswdf\").value;\r\n");
      out.write("        var phone = document.getElementById(\"yphonef\").value;\r\n");
      out.write("        if(username==\"\"||username==null){\r\n");
      out.write("            alert(\"请填写用户名\");\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(passwd==\"\"||passwd==null){\r\n");
      out.write("            alert(\"请填写密码\");\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(phone==\"\"||phone==null){\r\n");
      out.write("            alert(\"请填写手机号\");\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        username = strEncode(trim(username));\r\n");
      out.write("        passwd = strEncode(trim(passwd));\r\n");
      out.write("        phone = strEncode(trim(phone));\r\n");
      out.write("        $.post(\"");
      out.print(request.getContextPath());
      out.write("/login/validateNumByUserf.htm\",{\"username\":username,\"passwd\":passwd,\"phone\":phone,\"ts\":Math.random()}, function(data){\r\n");
      out.write("            if(data==\"0\"){\r\n");
      out.write("                alert(\"用户不存在!\");\r\n");
      out.write("            }else if(data==\"1\"){\r\n");
      out.write("                alert(\"输入密码不正确!\");\r\n");
      out.write("            }else if(data==\"2\"){\r\n");
      out.write("                alert(\"服务器繁忙,请稍后!\");\r\n");
      out.write("            }else if(data==\"4\"){\r\n");
      out.write("                alert(\"距离您前一个短信发送没超过24小时,请用之前短信验证码登录!\");\r\n");
      out.write("            }else if(data==\"5\"){\r\n");
      out.write("                alert(\"您已经绑定手机请正常登录!\");\r\n");
      out.write("            }else{\r\n");
      out.write("                curCount = count;\r\n");
      out.write("                $(\"#btnf\").attr(\"disabled\", \"disabled\");\r\n");
      out.write("                $(\"#btnf\").val(\"重新获取\" + curCount + \"秒\");\r\n");
      out.write("                InterValObj = window.setInterval(SetRemainTime, 1000);\r\n");
      out.write("            }\r\n");
      out.write("        });\r\n");
      out.write("    }\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("    function loginxtf(){\r\n");
      out.write("        var yusernamef = document.getElementById(\"yusernamef\").value;\r\n");
      out.write("        var ypasswdf = document.getElementById(\"ypasswdf\").value;\r\n");
      out.write("        var ynewpasswdf = document.getElementById(\"ynewpasswdf\").value;\r\n");
      out.write("        var ynewpasswdqrf = document.getElementById(\"ynewpasswdqrf\").value;\r\n");
      out.write("        var yphonef = document.getElementById(\"yphonef\").value;\r\n");
      out.write("        var keyf = document.getElementById(\"keyf\").value;\r\n");
      out.write("        if(yusernamef==null||yusernamef==\"\"){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'用户名不能为空!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(ypasswdf==null||ypasswdf==\"\"){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'原密码不能为空!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(ynewpasswdf==null||ynewpasswdf==\"\"){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'新密码不能为空!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(ynewpasswdf!=ynewpasswdqrf){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'两次新密码输入不一致!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(yphonef==null||yphonef==\"\"){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'手机号不能为空!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return;\r\n");
      out.write("        }\r\n");
      out.write("        if(keyf==null||keyf==\"\"){\r\n");
      out.write("            art.dialog({\r\n");
      out.write("                title:'提示 ',\r\n");
      out.write("                content:'短信验证码不能为空!',\r\n");
      out.write("                icon:'warning',\r\n");
      out.write("                lock:true,\r\n");
      out.write("                resize:false\r\n");
      out.write("            });\r\n");
      out.write("            return ;\r\n");
      out.write("        }\r\n");
      out.write("    }\r\n");
      out.write("</script>\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

有了上述概念基础后,继续

二、jsp脚本是什么?

jsp脚本就是一些能够在jsp页面写Java代码的标签,下面介绍3个最常用的:

1.<%...%>:内容会直接放到_jspService()方法之中,会被当做可执行的Java代码执行 

2.<%=…%>:内容会放到out.print()中,作为out.print()的参数,也就是直接可以在页面输出引用的内容

3.<%!…%>:内容会放到_jspService()方法之外,被类直接包含,就是定义成员变量

在前端写Java代码对于纯前端选手很不友好,写法也不伦不类,个人也深受其害,满篇乱七八糟,本来前端标签就够乱了,再夹杂大量jsp脚本,看起来简直就像是把客厅搬到大马路上,家里的事拿到大街上干,所以为了优化这个问题,引出下面的概念。

三、EL表达式

EL表达式语法:${expression} ,意思为获取域中存储的key为expression的数据

后台需要将参数放到域中,如通过modelmap:

1.后台将vo实体类塞满数据放入域中,反回work页面

2.在该页面通过EL表达式获取该实体类中工作单位属性的值

这里说到的域的概念不展开说了,简单补充下:

域对象:存储数据的区域。JavaWeb中的四大域对象,范围依次增大:

page:当前页面有效

request:当前请求有效

session:当前会话有效

application:当前应用有效

EL表达式获取数据,会依次从这4个域中寻找,直到找到为止,最常用的就是request与session

四、JSTL表达式

JSP标准标签库(Jsp Standarded Tag Library) ,使用标签取代JSP页面上的Java代码

标签库提供的标签非常多,这里只说最常用的标签<c:if,<c:foreach。

c:if 来完成逻辑判断,替换Java的if else,一般jstl标签与el表达式搭配使用,来判断EL表达式中的值。

如,将flag字段放入域中,通过EL表达式获取,判断后是否夺冠。

<c:if test="${flag == 1}">  

 夺冠

</c:if>

<c:forEach>:相当于 for 循环

items:被遍历的容器 var:遍历产生的临时变量 varStatus:遍历状态对象

实例如下,用jstl标签循环域中的motoLists集合:

<c:forEach items="${motoLists}" var="moto">
    <tr align="center">
        <td>${moto.id}</td>
        <td>${moto.brandName}</td>
        <td>${moto.companyName}</td>
        <td>${moto.description}</td>
    </tr>
</c:forEach>

以上代码用Java语言解释一遍就是:

for (Moto moto : motoLists) {
    Integer id = moto.getId();
    String imgUrl = moto.getImgUrl();
    String brandName = moto.getBrandName();
    String companyName = moto.getCompanyName();
}

针对于另一种变量自增的for循环:

for (int i = 0; i <= 10; i++) {
    System.out.println(i);
}

jstl表达式的写法与解释如下:

//begin:开始数
end:结束数
step:步长
<c:forEach begin="0" end="10" step="1" var="i">
    ${i}
</c:forEach>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/353071.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

嘿嘿,vue之输出土味情话

有点好玩&#xff0c;记录一下。通过按钮调用网站接口&#xff0c;然后解构数据输出土味情话。 lovetalk.vue: <!--vue简单框架--> <template> <!-- 这是一个div容器&#xff0c;用于显示土味情话 --> <div class"talk"> <!-- 当点…

华为机考入门python3--(4)牛客4-字符串分隔

分类&#xff1a;字符串 知识点&#xff1a; 复制符号* 复制3个0 0*3 000 字符串截取 截取第i位到j-1位 str[i:j] 题目来自【牛客】 input_str input().strip()# 先补齐 if len(input_str) % 8 ! 0: input_str 0 * (8 - len(input_str) % 8) # 每8个分 out…

第15次修改了可删除可持久保存的前端html备忘录:换了一个容器时钟,匹配背景主题:现代深色

第15次修改了可删除可持久保存的前端html备忘录&#xff1a;换了一个容器时钟&#xff0c;匹配背景主题&#xff1a;现代深色 备忘录代码 <!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8"><meta http-equiv&qu…

【安卓】不需要魔法使用AuthenticationApp解决Github报2FA双重验证警告的问题

如果你也收到了类似的警告信息&#xff0c;那就一起启用2FA吧​。 背景介绍 Github提供了四种2FA方式&#xff1a; AuthenticatorApp(今天要分享的就是这个)SMS/Text message: 由于SMS不支持国内手机号, 不可用Security keys: 由于该方式需要物理设备等&#xff0c;不好Githu…

数据库查询3

目录 1. 多表查询 1.1.1 介绍 1.1.2 分类 1.2 内连接 1.3 外连接 1.4 子查询 1.4.1 介绍 1.4.2 标量子查询 1.4.3 列子查询 1.4.4 行子查询 1.4.5 表子查询 2. 事务 2.1 操作 2.2 四大特性 数据库总结2 数据库总结1 1. 多表查询 1.1.1 介绍 多表查询&#xff…

vue3使用最新的属性defineModel实现父子组件数据响应式绑定

子父之间使用v-model双向绑定数据&#xff0c;子组件每次都要写emit和props觉得麻烦&#xff1f;以前&#xff0c;为了使组件支持与v-model双向绑定&#xff0c;它需要&#xff08;1&#xff09;声明prop&#xff0c;&#xff08;2&#xff09;在打算更新prop时发出相应的updat…

Keil导入文件的操作步骤

本文以STM32G431R8T6导入lcd.c文件为例 1 背景 作为最常用的单片机程序编辑工具&#xff0c;全球有超过10万的工程师在使用Keil&#xff0c;但初学者很有可能对Keil的各种信息和操作一无所知&#xff0c;我便是其中一员&#xff0c;由于最近看了很多Keil相关的教程&#xf…

3DGS 其二:Street Gaussians for Modeling Dynamic Urban Scenes

3DGS 其二&#xff1a;Street Gaussians for Modeling Dynamic Urban Scenes 1. 背景介绍1.1 静态场景建模1.2 动态场景建模 2. 算法2.1 背景模型2.2 目标模型 3. 训练3.1 跟踪优化 4. 下游任务 Reference&#xff1a; Street Gaussians for Modeling Dynamic Urban Scenes 1.…

微信小程序之页面导航、生命周期和WXS脚本

学习的最大理由是想摆脱平庸&#xff0c;早一天就多一份人生的精彩&#xff1b;迟一天就多一天平庸的困扰。各位小伙伴&#xff0c;如果您&#xff1a; 想系统/深入学习某技术知识点… 一个人摸索学习很难坚持&#xff0c;想组团高效学习… 想写博客但无从下手&#xff0c;急需…

Genome-wide association studies in R

全基因组关联&#xff08;GWA&#xff09;研究扫描整个物种基因组&#xff0c;寻找多达数百万个SNPs与特定感兴趣特征之间的关联。值得注意的是&#xff0c;感兴趣的性状实际上可以是归因于群体的任何类型的表型&#xff0c;无论是定性的&#xff08;例如疾病状态&#xff09;还…

分布式数据实现跨设备数据同步的N个秘密 | 分布式数据管理解析(二)

上期我们给大家带来分布式数据管理如何完成数据存储&#xff0c;数据同步&#xff0c;数据跨端访问&#xff0c;并保证整个过程中跨设备数据安全的解读。 这都得益于分布式数据管理平台抽象出的三大关键技术——分布式数据库&#xff0c;分布式文件系统和融合搜索。 那么这三…

Scrapy IP()类 编程指南(基础)

Scrapy IP()类 编程指南&#xff08;基础&#xff09; IP简介 工欲善其事&#xff0c;必先利其器&#xff0c;在聊Scapy IP类时&#xff0c;我们先要了解IP是什么。 IP指的是Internet Protocol&#xff08;互联网协议&#xff09;的数据包。Internet Protocol是互联网上用于在…

取消Vscode在输入符号时自动补全

取消Vscode在输入符号时自动补全 取消Vscode在输入符号时自动补全问题演示解决方法 取消Vscode在输入符号时自动补全 问题演示 在此状态下输入/会直接自动补全, 如下图 笔者想要达到的效果为可以正常输入/而不进行补全, 如下图 解决方法 在设置->文本编辑器->建议, 取消…

经典目标检测YOLO系列(三)YOLOV3的复现(1)总体网络架构及前向处理过程

经典目标检测YOLO系列(三)YOLOV3的复现(1)总体网络架构及前向处理过程 和之前实现的YOLOv2一样&#xff0c;根据《YOLO目标检测》(ISBN:9787115627094)一书&#xff0c;在不脱离YOLOv3的大部分核心理念的前提下&#xff0c;重构一款较新的YOLOv3检测器&#xff0c;来对YOLOv3有…

<蓝桥杯软件赛>零基础备赛20周--第19周--最短路

报名明年4月蓝桥杯软件赛的同学们&#xff0c;如果你是大一零基础&#xff0c;目前懵懂中&#xff0c;不知该怎么办&#xff0c;可以看看本博客系列&#xff1a;备赛20周合集 20周的完整安排请点击&#xff1a;20周计划 每周发1个博客&#xff0c;共20周。 在QQ群上交流答疑&am…

OpenCV-28 全局二值化

一、形态学概念 什么是形态学&#xff1f; 1&#xff09;指一系列处理图像型状特征的图像处理技术 2&#xff09;形态学的基本思想是利用一直特殊的结构元&#xff08;本质上是卷积核&#xff0c;且这个卷积核的值只有1和0&#xff09;来测量或提取输入图像中相应的型状或特…

17. Spring Boot Actuator

17. Spring Boot Actuator Spring Boot执行器(Actuator)提供安全端点&#xff0c;用于监视和管理Spring Boot应用程序。 默认情况下&#xff0c;所有执行器端点都是安全的。 在本章中&#xff0c;将详细了解如何为应用程序启用Spring Boot执行器。 启用Spring Boot Actuator …

CAD-autolisp(三)——文件、对话框

目录 一、文件操作1.1 写文件1.2 读文件 二、对话框DCL2.1 初识对话框2.2 常用对话框界面2.2.1 复选框、列表框2.2.2 下拉框2.2.3 文字输入框、单选点框 2.3 Lisp对dcl的驱动2.4 对话框按钮实现拾取2.5 对话框加载图片2.5.1 幻灯片图片制作2.5.1 代码部分 一、文件操作 1.1 写…

架构篇28:业务高可用的保障-异地多活架构

文章目录 应用场景架构模式小结无论是高可用计算架构,还是高可用存储架构,其本质的设计目的都是为了解决部分服务器故障的场景下,如何保证系统能够继续提供服务。但在一些极端场景下,有可能所有服务器都出现故障。例如,典型的有机房断电、机房火灾、地震、水灾……这些极端…

【阿里云服务器数据迁移】 同一个账号 不同区域服务器

前言 假如说一台云服务器要过期了,现在新买了一台,有的人会烦恼又要将重新在新的服务器上装环境,部署上线旧服务器上的网站项目, 但是不必烦恼,本文将介绍如何快速将就旧的服务器上的数据迁移到新的服务器上. 包括所有的环境和网站项目噢 ! 步骤 (1) 创建旧服务器自定义镜像…