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

news2024/11/16 5:35:01

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>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

一键搭建《幻兽帕鲁》服务器

幻兽帕鲁越来越火&#xff0c;官方服务器不堪重负&#xff0c;不少玩家有搭建幻兽帕鲁私服的想法&#xff0c;但又碍于对计算机知识的匮乏而不敢动手&#xff0c;现在它来了&#xff0c;马云家的云服务器一键搭建幻兽帕鲁服务器&#xff0c;一站式解决&#xff01;&#xff01;…

C# 设置一个定时器函数

C#中&#xff0c;创建设置一个定时器&#xff0c;能够定时中断执行特定操作&#xff0c;可以用于发送心跳、正计时和倒计时等。 本文对C#的定时器简单封装一下&#xff0c;哎&#xff0c;以方便定时器的创建。 定义 using Timer System.Timers.Timer;class SetTimer {Timer …

智慧文旅:提升旅游体验与推动经济发展的新动力

一、智慧文旅的定义与意义 智慧文旅&#xff0c;即智慧文化旅游&#xff0c;是一种以当地特色文化元素为核心驱动&#xff0c;利用现代科技手段实现旅游景区全面智慧升级的旅游模式。其意义在于为游客提供高效便捷的旅游信息化服务&#xff0c;提升旅游体验&#xff0c;同时推…

谷粒商城【成神路】-【1】——项目搭建

目录 &#x1f95e;1.整体架构图 &#x1f355;2.微服务划分图 &#x1f354;3.开发环境 &#x1f354;4.搭建git &#x1f32d;5.快速搭建服务 &#x1f37f;6.数据库搭建 &#x1f9c2;7.获取脚手架 &#x1f953;8.代码生成器 &#x1f373;9.创建公共模块 …

【Vue】1-1、webpack的基本使用

一、什么是 Webpack 概念&#xff1a; webpack 是前端项目工程化的具体解决方案。 主要功能&#xff1a; 它提供了友好的前端模块化开发支持&#xff0c;以及代码压缩混淆、处理浏览器端 JavaScript 的兼容性、性能化等强大的功能。 好处&#xff1a; 让程序员把工作重心放到具…

一些反序列化总结

1 反序列化漏洞原理 如果反序列化的内容就是那串字符串&#xff0c;是用户可以控制的&#xff08;即变量的值&#xff09;&#xff0c;且后台不正当的使用了PHP中的魔法函数&#xff0c;就会导致反序列化漏洞&#xff0c;可以执行任意命令。Java 序列化指 Java 对象转换为字节序…

C#,数据检索算法之跳跃搜索(Jump Search)的源代码

数据检索算法是指从数据集合&#xff08;数组、表、哈希表等&#xff09;中检索指定的数据项。 数据检索算法是所有算法的基础算法之一。 本文提供跳跃搜索的源代码。 1 文本格式 using System; namespace Legalsoft.Truffer.Algorithm { public static class ArraySe…

港科夜闻|香港科大科研实力受肯定,成立三个赛马会创科实验室,推展数据科学,再生生物学及气候变化研究...

关注并星标 每周阅读港科夜闻 建立新视野 开启新思维 1、香港科大科研实力受肯定&#xff0c;成立三个赛马会创科实验室&#xff0c;推展数据科学、再生生物学及气候变化研究。香港科大近日获香港赛马会慈善信托基金慷慨捐助港币三千万元&#xff0c;成立三个赛马会创科实验室&…

微信小程序(十七)自定义组件生命周期(根据状态栏自适配)

注释很详细&#xff0c;直接上代码 上一篇 新增内容&#xff1a; 1.获取手机状态栏的高度 2.验证attached可以修改数据 3.动态绑定样式数值 源码&#xff1a; myNav.js Component({lifetimes:{//相当于vue的created,因为无法更新数据被打入冷宫created(){},//相当于vue的mount…

java------抽象类和接口【详解】

目录 一.抽象类 1.1抽象类的定义&#xff1a; 1.2抽象类的语法&#xff1a; 1.3 抽象类的特性&#xff1a; 二.接口 2.1接口概念&#xff1a; 2.2 接口的语法&#xff1a; 2.3接口的使用&#xff1a; 2.4接口的特性&#xff1a; 2.5多个接口的实现&#xff1a; 2.6抽象…

接口测试怎么测?接口测试的流程和步骤(超详细)

&#x1f345; 视频学习&#xff1a;文末有免费的配套视频可观看 &#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;薪资嘎嘎涨 一、什么是接口测试 我们要想知道接口测试怎么做&#xff0c;首先要明白接口测试是什么?一般…

Tomcat怎么优化

目录 性能方面的优化&#xff1a; 安全方面的优化&#xff1a; 引言&#xff1a;面试官问到的Tomcat怎么优化&#xff0c;这两个方面直接得到他认可&#xff01;&#xff01; 性能方面的优化&#xff1a; 内存优化&#xff1a;-Xms java虚拟机初始化时的最小内存、-Xmx java虚…

C++多态深度剖析

文章目录 1. 前言2. 多态的概念及定义2.1 概念2.2 多态的构成条件2.3 虚函数2.4 虚函数的重写2.5 override 和 final2.5 重载、覆盖(重写)、隐藏&#xff08;重定义&#xff09;的对比 3. 抽象类3.1 概念3.2 接口继承和实现继承 4. 多态的原理4.1 虚函数表4.2 多态的原理4.3 动…

《30天自制操作系统》 第一周(D1-D7) 笔记

前言&#xff1a;这是我2023年5月份做的一个小项目&#xff0c;最终是完成了整个OS。笔记的话&#xff0c;只记录了第一周。想完善&#xff0c;却扔在草稿箱里许久。最终决定&#xff0c;还是发出来存个档吧。 一、汇编语言 基础指令 MOV: move赋值&#xff0c;数据传送指令…

UE4 CustomDepthMobile流程小记

原生UE opaque材质中获取CustomDepth/CustomStencil会报错 在其Compile中调用的函数中没有看到报错逻辑 材质节点的逻辑都没有什么问题&#xff0c;所以看一下报错 在HLSLMaterialTranslator::Translate中 修改之后 mobile流程的不透明材质可以直接获取SceneTexture::customd…

Pyroch中transforms 图像增强发方法的应用

1 应用场景 在我们训练模型的时候&#xff0c;有的时候数据不够&#xff0c;就需要通过水平翻转、垂直翻转、镜像、旋转、改变亮度、标准化等方式增加图像的多样性&#xff0c;此时可以调用Pytorch 中的Transforms完成这些操作 2 导入相应的库 from torchvision import tran…

蓝桥杯-sort排序(上)

sort排序 &#x1f388;1.算法说明&#x1f388;2.例题&#x1f52d;2.1例题一&#x1f52d;2.2例题二&#x1f52d;2.3例题三&#x1f52d;2.4例题四&#x1f52d;2.5例题五&#x1f52d;2.6例题六 &#x1f388;1.算法说明 &#x1f50e;对于一个数组&#xff0c;通过对数组中…

【html+css+js】实现图片轮播效果

简单实现 <html><head><style type"text/css">*{background-color:green;}#lunbo{ width:600px; height:600px;position:relative;left:100px;top:50px;} //定义轮播图片所显示的位置ul{width:100%; height:100%; position:relative;left:0px;top…

基于 SpringBoot+Vue 的读书笔记共享平台的研究与实现,附源码,文档

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝30W、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;…

K8s 安装部署-Master和Minion(Node)文档

K8s 安装部署-Master和Minion(Node)文档 操作系统版本&#xff1a;CentOS 7.4 Master &#xff1a;172.20.26.167 Minion-1&#xff1a;172.20.26.198 Minion-2&#xff1a;172.20.26.210&#xff08;后增加节点&#xff09; ETCD&#xff1a;172.20.27.218 先安装部署ETC…