Rookie JSP (1)

zhaozj2021-02-16  49

Due to the interest of Java, I started learning Java a year ago, I'm an anxious and painful for beginners in the eyes of old birds. Now I will share some experience in learning JSP. Since the level is limited, the mistake is inevitable, I hope that the old birds will not be enlighten, in order to work together.

It is said to introduce JSP but because of its complicated content, I will only focus on the use of JSP Tags. But before this, you will briefly introduce the basic knowledge of JSP, and all implementations are in the Win2000 environment.

Said so much, then what is JSP. JSP full name is Java Servlet Page, which is a text-based piece. It can display static content like HTML, SVG, WML, XML, can also process dynamic content like PHP, ASP, such as: Database.

Let's take a look at what JSP is long.

<% @ Page ContentType = "Text / HTML; Charset = GBK"%> hello </ title> </ head> <h1> <% = "Hello the world"%> //// ********** </ h1> <body bgcolor = "# 00fff"> <b> Hello the world </ b> </ body> </ html></p> <p>Code 1</p> <p>It seems that it is not difficult. Friends who are familiar with HTML must soon find that the above code is almost exactly the same as HTM. But I think it is easy to guess what it means, nothing more than "Hello the World" is displayed. Maybe someone wants to ask, to display static content directly with HTML to be implemented. Yes, but from the above, JSP can also give a replacement for static display, which seems to imply the power of JSP (especially the TAG I will focus on). With the deepening of learning, this will change significantly.</p> <p>The process and servlets of the JSP page processing request are similar (actually each JSP page will be built into a corresponding servlet). So the Lifecycle of JSP depends on different vendors to implement the servlet. However, when requesting the JSP page, there will be a corresponding servlet processing. And the server will automatically compare the JSP page with its corresponding servlet If the discovery page is updated, it will automatically compile new pages (unless the server is considered to change the server settings). This is very convenient to write and debugging.</p> <p>It is said that many people have already tickle early (I am also a new Southam, I am most annoying, I won't have anything about it.). Below we come to Run just the JSP page.</p> <p>If you want to make JSP can get up, you first need a server program that supports JSP. I recommend Tomcat, no friends can go to http://jakarta.apache.org download (free). Of course, JDK is also essential (you can download) with http://java.sun.com. After installation, you also need to set the environment variable - Java_Home, which is the directory you install JDK. After setting, you will restart the machine. After the% CATALINA_HOME% / BIN / Startup (under Windows). Then you can play in your IE as: http: //127.0.0.1: 8080 / If you see the Tomcat's index.html page, you have no problem with your installation (note that due to Tomcat to occupy 8080 port, When Startup, you must guarantee that the 8080 port is not occupied). Only did you still do a JSP page, you first open Tomcat installation directory, my D: / server / tomcat below it will find a directory called WebApps (I use Tomcat4.0.1 Different versions may vary, if you can refer to the documentation provided by Tomcat, create a directory under WebApps, such as: HOME, then build directory web-inf (this directory is Tomcat requirement, must be established, and Pay attention to the case), and then establish an XML file called Web.xml under web-infers, the content is:</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! Doctype web-app public "- // sun microsystems, incaps//dtd web application 2.3 // en" "http://java.sun.com/dtd/web-app_2_3.dtd"></p> <p><web-app> </ web-app></p> <p>Below is the last step. Create a directory named JSP under Home, and establish a Hello.jsp file under the JSP is Code 1. And then restart Tomcat and in IE http://127.0.0.1:8080/home/jsp/hello.jsp.bingo! You can see the victory.</p> <p>It's good to say this today. It should be resting in so many things. See you later.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-23712.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="23712" 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.041</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 = 'jp2heyMT_2FCVZ8eEBvW6tT4xjr7YcI8c_2BX4390Gx1Iw4xFAAsn_2BrZAmAAsT1xhJbxF2RViiXbk9Os1R_2BZjliGHw_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>