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.HttpJspBaseimplements 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>

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Hive3.1.3基础(续)

参考B站尚硅谷 分区表和分桶表 分区表 Hive中的分区就是把一张大表的数据按照业务需要分散的存储到多个目录&#xff0c;每个目录就称为该表的一个分区。在查询时通过where子句中的表达式选择查询所需要的分区&#xff0c;这样的查询效率会提高很多。 分区表基本语法 分区表…

【linux】Debian挂起和休眠

一、挂起和休眠 在Debian桌面系统中&#xff0c;挂起和休眠是两种不同的状态&#xff0c;它们之间有一些区别。 挂起&#xff08;Suspend&#xff09;是将当前系统的状态保存到RAM&#xff08;内存&#xff09;中&#xff0c;然后关闭所有硬件设备&#xff0c;除了RAM之外。在…

如何在美国硅谷高防服务器上运行自定义的脚本和应用程序

在美国硅谷高防服务器上运行自定义的脚本和应用程序需要一定的技术和知识。下面我们将介绍一些关键步骤&#xff0c;帮助您顺利地在这些服务器上运行自定义应用程序和脚本。 确保您有对服务器的访问权限&#xff0c;并且已经通过SSH等方式连接到服务器。接下来&#xff0c;您可…

Zabbix交换分区使用率过高排查

Zabbix High swap space usage 问题现象 Zabbix 出现Highswap space usage(less than 50% free)告警&#xff0c;提示交换分区空间使用率超过50% 处理过程 1. 确定swap分区是否已占满 free -h登录Zabbix服务器检查内存情况&#xff0c;检查发现Linux服务器空闲的内存还有不少…

相机与镜头

一、相机视场 相机的视场角&#xff0c;也就是相机能够看到物像角度的最大值&#xff0c;视场角与焦距的关系为像高f*tan(fov/2)。由于相机的感光面是矩形&#xff0c;所以相机能够看到的区域也是矩形。探究相机的视场角&#xff0c;便于分析物面上那些区域属于相机盲区&#x…

宝塔面板一键部署幻兽帕鲁联机服务器教程

幻兽帕鲁是一款深受玩家喜爱的多人在线游戏&#xff0c;玩家可以自行搭建联机服务器&#xff0c;邀请亲朋好友一起在世界探索畅玩&#xff0c;为了方便玩家更快速的部署自己的幻兽帕鲁联机服务器&#xff0c;宝塔面板推出了幻兽帕鲁一键部署服务&#xff0c;一键即可安装并调整…

微信小程序(十九)组件通信(子传父)

注释很详细&#xff0c;直接上代码 上一篇 新增内容&#xff1a; 1.定义触发事件向父组件传输数据 2.父组件绑定绑定触发事件并获取数据 源码&#xff1a; myNav.wxml <view class"navigationBar custom-class" style"padding-top: {{test}}px;">&l…

Elasticsearch:聊天机器人、人工智能和人力资源:电信公司和企业组织的成功组合

作者&#xff1a;来自 Elastic Jrgen Obermann, Piotr Kobziakowski 让我们来谈谈大型企业人力资源领域中一些很酷且改变游戏规则的东西&#xff1a;生成式 AI 和 Elastic Stack 的绝佳组合。 现在&#xff0c;想象一下大型电信公司的典型人力资源部门 — 他们正在处理一百万件…

关系三元组抽取方案

一、流程概览 先用序列标注模型预测句子中的实体&#xff0c;再对实体&#xff08;加上句子&#xff09;走关系分类模型&#xff0c;预测实体的关系&#xff0c;最后形成有效的三元组。 1、数据标注 2、数据处理 处理原始数据得到ner命名实体识别的训练预测数据和关系抽取训…

CSS 双色拼接按钮效果

<template><view class="sss"><button> <!-- 按钮 --><view class="span"> 按钮 </view> <!-- 按钮文本 --></button></view></template><script></script><style>body {b…

能替代微软AD的国产化方案,搭建自主可控的身份管理体系

随着国产化替代步伐加速&#xff0c;以及企业出于信息安全建设的需要&#xff0c;越来越多的企业和组织开始考虑将现有的微软 Active Directory&#xff08;AD&#xff09;替换为国产化的LDAP身份目录服务&#xff08;也称统一身份认证和管理&#xff09;系统。本文将介绍一种国…

figure方法详解之Figure的创建与配置

figure方法详解之Figure的创建与配置 一 matplotlib.pyplot.figure二 Figure.set_size_inches()三 Figure.set_dpi()四 Figure.set_facecolor()五 Figure.set_edgecolor()六 Figure.set_alpha()七 Figure.set_linewidth()八 总结 在数据可视化中&#xff0c;Matplotlib是一个强…

语义分割(3):损失函数解析

文章目录 1. 常见语义分割损失1.1 Cross Entropy1.2 dice Loss1.2.1 为什么使用Dice loss1.2.2 公式1.2.3 Dice loss 和 F1-score代码 1.3 focal loss1.3.1 公式&#xff1a;1.3.2 代码 2. 语义分割损失应用参考 语义分割任务实际上是一种像素层面上的分类&#xff0c;需要识别…

跨平台Recorder录音插件:支持多种格式、音频可视化、实时上传、语音识别

视频教程地址&#xff1a;【跨平台Recorder录音插件&#xff1a;支持多种格式、音频可视化、实时上传、语音识别】 https://www.bilibili.com/video/BV1jQ4y1c7e4/?share_sourcecopy_web&vd_sourcee66c0e33402a09ca7ae1f0ed3d5ecf7c /** 先引入Recorder &#xff08; 需先…

2024-01-26-redis集群

为什么要搭建集群 高可用性&#xff1a;Redis集群可以提供高可用性&#xff0c;即使其中的一台节点发生故障&#xff0c;其他节点仍然可以继续提供服务。当一个节点下线时&#xff0c;集群会自动将负载均衡到其他可用节点上&#xff0c;从而保证系统的稳定性和可用性。 扩展性…

移动端打包成功后禁止生成 report.html 文件,并不自动打开该文件

目录 【问题】移动端 npm run build 打包后生成并打开 report.html 文件package.json 文件vue.config.js 代码 【解决】打包后去除 report.html 文件vue.config.js 代码 参考 【问题】移动端 npm run build 打包后生成并打开 report.html 文件 package.json 文件 {"name&…

大数据安全 | 期末复习(中)

文章目录 &#x1f4da;感知数据安全⭐️&#x1f407;传感器概述&#x1f407;传感器的静态特性&#x1f407;调制方式&#x1f407;换能攻击&#x1f407;现有防护策略 &#x1f4da;AI安全⭐️&#x1f407;智能语音系统——脆弱性&#x1f407;攻击手段&#x1f407;AI的两…

springboot快速写接口

1. 建proj形式 name会变成文件夹的名字&#xff0c;相当于你的项目名称 基础包 2. 基础依赖 3. 配置数据库 这里要打开mysql&#xff0c;并且创建数据库 方法&#xff1a; 安装好数据库&#xff0c;改好账号密码用navicat来建表和账号配置properties.yml文件即可 4.用res…

实现负载均衡

1.安装依赖 sudo apt insta11 libgd-dev 2.下载nginx wget http://nginx.org/download/nginx-1.22.1.tar.gz 3.解压nginx tar -zvxf nginx-1.22.1.tar.g2 4.编译安装 cd nginx-1.22.1 5.编译并指定安装位置&#xff0c;执行安装之后会创建指定文件夹/www/env/nginx ./configure…

【阻塞队列】阻塞队列的模拟实现及在生产者和消费者模型上的应用

文章目录 &#x1f4c4;前言一. 阻塞队列初了解&#x1f346;1. 什么是阻塞队列&#xff1f;&#x1f345;2. 为什么使用阻塞队列&#xff1f;&#x1f966;3. Java标准库中阻塞队列的实现 二. 阻塞队列的模拟实现&#x1f35a;1. 实现普通队列&#x1f365;2. 实现队列的阻塞功…