Event-driven Web Tour - JSP and JavaScript fusion (continued)

zhaozj2021-02-16  48

Let's talk about JSP and JavaScript for use and interviews. Maybe you have used Delphi's WebBroker to develop Web Application When you do one thing (submit) is a WebAction, it is a function. And this function has become a page under ASP and JSP conditions. However, you should also understand them into a function, a function that returns a string. And this string is that you use the results you see by the View Source File menu command. In this way, the issue of JavaScript call Java variables is solved. The string returned by our JSP has a JavaScript code, and these code is performed by the browser. Since the generation of JavaScript code can be dynamically generated by JSP, JavaScript can contain JSP code running results. This enables JavaScript calls to JSP variables. Let's take a look later, JavaScript calls to JSP methods and JSP to JavaScript. These two calls have a common point, which is to submit the page, and set several hidden parameters with Hidden. JSP can be processed according to the corresponding parameters, it is possible. Maybe some people have not understood, then we still use a program to explain the problem! Procedure 2: A server gets a web page for client information. He obtained some screen settings of the client and record them in the database. GetClientInfo.jsp

<% @ page contenttype = "text / html; charset = uTF-8" Language = "java"%>

<% @ import = "java.sql. *"%>

information </ title></p> <p><Meta http-equiv = "content-type" content = "text / html; charSet = UTF-8"></p> <p><Style type = "text / css"></p> <p>Table, Body {</p> <p>Font-Family: "Courier New";</p> <p>FONT-SIZE: 10PT;</p> <p>}</p> <p></ Style></p> <p></ HEAD></p> <p><Body></p> <p><%</p> <p>IF (Request.GetParameter ("ishavedata") == null) {%></p> <p><Form name = "frmclient" method = "post"></p> <p><Input type = "hidden" name = "ishavedata" value = ">></p> <p><Input Type = "Hidden" name = "iscreenwidth"></p> <p><Input type = "hidden" name = "iColorDepth"></p> <p><Input Type = "Hidden" name = "iscreenheight"></p> <p><Input Type = "Hidden" name = "sbrowsename"></p> <p><Input type = "hidden" name = "sbrowsever"> <input type = "hidden" name = "iClientHeight"></p> <p><Input Type = "Hidden" name = "iClientWidth"></p> <p><Script language = "javascript1.4" type = "text / javascript"></p> <p>FRMCLIENT.Iscreenwidth.Value = Screen.width;</p> <p>FRMCLIENT.ISCREENHHHT.VALUE = Screen.Height;</p> <p>FRMCLIENT.ICOLORDEPTH.VALUE = Screen.colorDepth;</p> <p>FRMCLIENT.SBROWSENAME.VALUE = Navigator.Appname;</p> <p>FRMCLIENT.SBROWSEVER.VALUE = Navigator.AppVersion;</p> <p>FRMCLIENT.ICLIENTHEIGHT.VALUE = Screen.Availheight;</p> <p>FRMCLIENT.ICLIENTWIDTH.VALUE = Screen.availswidth;</p> <p>FRMCLIENT.SUBMIT ();</p> <p></ Script></p> <p></ Form></p> <p><%} else {%></p> <p><Object id = objmsagent</p> <p>ClassID = CLSID: D45FD31B-5C6E-11D1-9EC1-00C04FD7081F</p> <p>Width = "32" Height = "32"></p> <p></ Object></p> <p><Script language = "javascript1.4" type = "text / javascript"></p> <p>Var Merlinid;</p> <p>VAR Merlinacs;</p> <p>Objmsagent.connected = true;</p> <p>MerlinLoaded = loadingLocalagent (Merlinid, Merlinacs);</p> <p>Merlin = objmsagent.characters.Character (Merlinid);</p> <p>Merlin.show ();</p> <p>Merlin.Play ("surprised");</p> <p>Merlin.speak ("<% =" Hello? "%>");</p> <p>Merlin.Play ("GestureLeft");</p> <p>Merlin.Think ("<% =" this is a jsp variant "%>");</p> <p>Merlin.Play ("pleased");</p> <p>Merlin.think ("<% =" JavaScript Uses JSP Variants "%>");</p> <p>Merlin.Play ("GestureDown");</p> <p>Merlin.speak ("<% =" bye! SO Easy! "%>");</p> <p>Merlin.hide ();</p> <p>Function loadLocalagent (charid, characs) {</p> <p>LoadReq = objmsagent.characters.Load (Charid, Characs);</p> <p>Return (True);</p> <p></ Script></p> <p><Table></p> <p><TR> <TD COLSPAN = "2"></p> <p><Font color = "# ff0000"> Your Infomation: </ font></p> <p></ Td> </ tr></p> <p><Tr> <TD> Screen Width: </ TD></p> <p><TD> <% = Request.getParameter ("Iscreenwidth")%> </ td> </ tr></p> <p><Tr> <TD> Screen Height: </ TD></p> <p><TD> <% = Request.getParameter ("IscreenHeight")%> </ td> </ tr></p> <p><TR> <TD> Color Depth: </ TD></p> <p><TD> <% = Request.getParameter ("IcolorDepth")%> </ td> </ tr></p> <p><TR> <TD> Browse: </ td></p> <p><TD> <% = Request.getParameter ("sbrowsename")%> </ td> </ tr></p> <p><TR> <TD> Browse: </ td></p> <p><TD> <% = Request.getParameter ("sbrowsever")%> </ td> </ tr></p> <p><TR> <TD> Client Area Width: </ TD></p> <p><TD> <% = Request.getParameter ("iClientWidth")%> </ td> </ tr></p> <p><TR> <TD> Client Area Height: </ TD></p> <p><TD> <% = Request.getParameter ("IclientHeight")%> </ td> </ tr></p> <p></ TABLE></p> <p><% String strdsn =</p> <p>"JDBC: ODBC: driver = {Microsoft Access Driver (* .mdb)}; dbq ="</p> <p> Application.getRealPath ("// Web-INF // msg.mdb");</p> <p>CONNECTION CNCT = NULL;</p> <p>Statement Stmt = NULL;</p> <p>Class.Forname ("Sun.jdbc.odbc.jdbcodbcdriver");</p> <p>CNCT = DriverManager.getConnection (strdsn, "," ");</p> <p>STMT = cnct.createstatement</p> <p>ResultSet.Type_Scroll_InSensitive,</p> <p>ResultSet.concur_updatable;</p> <p>Java.text.dateFormat DFNOW =</p> <p>Java.text.dateFormat.getdateTimeInstance (</p> <p>Java.text.dateformat.medium, java.text.dateformat.medium);</p> <p>String strdate = dfnow.format (new java.util.date ());</p> <p>String sinsertsql = "Insert Into Clientmsg Values" </p> <p>"/ '" Request.getRemoteAddr () "/'," </p> <p>"/ '" strdate "/'," </p> <p>"/ '" Request.getParameter ("Iscreenwidth") "/'," </p> <p>"/ '" Request.getParameter ("IscreenHeight") "/'," </p> <p>"/ '" Request.getParameter ("IcolorDepth") "/'," </p> <p>"/ '" Request.GetParameter ("SBROWSENAME") "/'," </p> <p>"/ '" Request.getParameter ("SBROWSever") "/'," </p> <p>"/ '" Request.GetParameter ("iClientWidth") "/'," </p> <p>"/ '" Request.getParameter ("iClientHeight") ");";</p> <p>Stmt.executeUpdate (SINSERTSQL);%></p> <p><P> <font color = "# ff0000"></p> <p>The Information of Other Visitors: </ font> </ p></p> <p><% Resultset = stmt.executeQuery ("SELECT * from clientmsg");</p> <p>While (rs.next ()) {%></p> <p><Table></p> <p><TR> <TD COLSPAN = "2"> <hr size = "1"> </ td> </ tr></p> <p><TR> <TD COLSPAN = "2"> <strong></p> <p><Font color = "# 0000ff"> <% = rs.getstring ("ip")%> AT</p> <p><% = Rs.getstring ("time")%> Visited this Page</p> <p></ Font> </ strong> </ td> </ tr></p> <p><Tr> <TD> Screen Width: </ TD></p> <p><TD> <% = rs.getstring ("screenwidth")%> </ td> </ tr> <tr> <td> screen height: </ td></p> <p><TD> <% = rs.getstring ("ScreenHeight")%> </ td> </ tr></p> <p><TR> <TD> Color Depth: </ TD></p> <p><TD> <% = rs.getstring ("colorDepth")%> </ td> </ tr></p> <p><TR> <TD> Browse: </ td></p> <p><TD> <% = rs.getstring ("browsename")%> </ td> </ tr></p> <p><TR> <TD> Browse: </ td></p> <p><TD> <% = rs.getstring ("browsever")%> </ td> </ tr></p> <p><TR> <TD> Client Area Width: </ TD></p> <p><TD> <% = rs.getstring ("ClientWidth")%> </ td> </ tr></p> <p><TR> <TD> Client Area Height: </ TD></p> <p><TD> <% = rs.getstring ("ClientHeight")%> </ td> </ tr></p> <p></ TABLE></p> <p><%}</p> <p>Rs.close ();</p> <p>RS = NULL;</p> <p>Stmt.close ();</p> <p>CNCT.CLOSE ();</p> <p>STMT = NULL;</p> <p>CNCT = NULL;</p> <p>}</p> <p>%></p> <p><br></p> <p></ Body></p> <p></ Html></p> <p>When this web is run, you first use JavaScript to get the client's information, then automatically submit the page, and then the JSP will record the corresponding information and save it in the database, and then read all the visits from the database. In this program, I also called Msagent that all the words he displayed is a JSP variable, of course you can also set it.</p> <p>This program also uses the database, which is AccSess, a file that places yourapp% / web-inf / msg.mdb. There is a table clientmsg. There are a few fields:</p> <p>Good example is a full!</p> <p>Maybe you will say, isn't it submit?</p> <p>Yes, the next time we speak is the art of submitting.</p> <p>(Operating environment IE6, Tomcat4.1.x jdk1.4.x)</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-28337.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="28337" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.046</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'ELWi4vai2ytPP0A_2BEk0_2FjZe5xzemfFq2_2FRrU1wCbRX4ciSjOzn4cdJNnDZc_2BBNpwgIfXhlbbhVZjCnpydVreVg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>