Tomcat learning notes

xiaoxiao2021-03-06  40

◎ When using the start method under Tomcat Bin, there is no debugging information, and the DOS window closes the RUN method under Tomcat BIN, there is an error in Tomcat, and there will be any debugging information, and the DOS window ◎ still open ServletContext can be obtained by a process getServletContext httpservletrequest then obtained by getRequestDispatcher servletcontext RequestDispatch objects through the object such that the forward current servlet is to control or to other jsp servlet // forward using the specific code: public void doPost (HttpservletRequest Request, httpservletresponse response) throws servletexception, ioException {

// Get the username from the request.getParameter ("username"); // get the password from the request.getParameter ("password");

// Add the user to the request requirements.setttribute ("user", username); Request.SetAttribute ("password", password);

// forward the request to the target named servletcontext context = getServletContext ();

System.out.println ( "Redirecting to" target); RequestDispatcher dispatcher = context.getRequestDispatcher (target); dispatcher.forward (request, response);} procedure: httpservletrequest-> servletContext-> taglib a development instance RequestDispatcher ◎ 1 . Define Taglib2. Define JSP TAG3. Taglib statement 4 is defined in the web.xml file. Define Tag file 1.package mypack; import javax.servlet.jsp.jspexception; import javax.servlet.jsp.jsptagexception; import javax.servlet.jsp.tagext.tagsupport;

Public class hellotag extends tagsupport {public hellotag () {

}

//Method caled when closing hello tag is encountered public int doendtag () throws jspexception {

Try {

// we use the pagecontext to get a writer // we thrint The text string hello pagecontext.get (). Print ("Hello");} catch (Exception E) {

Throw new jsptagexception (E.GETMESSAGE ());} // We want to return Skip_body Because this Tag does not support // a tag body return skip_body;} public void release () {

// Call The Parent's Release To Release Any Resources // Used by The Parent Tag. // This Is Just Good Practice for When You Start Creating // Hierarchies of Tags. Super.Release ();}}

2. <% @ Taglib URI = "/ MyTaglib" prefix = "mm"%> helloApp </ title> </ head> <body> <b> <mm: hello />: <% = Request.GetaTribute ("User")%> </ b> </ body> </ html> 3. <? XML Version = "1.0" eNCoding = "ISO-8859-1">></p> <p><! Doctype web-app public '- // sun microsystems, Inc.//dtd Web Application 2.3 // en' 'http://java.sun.com/j2ee/dtds/web-app_2_3.dtd'></p> <p><web-app></p> <p><servlet> <servlet-name> dispatcher </ servlet-name> <servlet-class> mypack.dispatcherservlet </ servlet-class> </ servlet></p> <p><servlet-mapping> <servlet-name> dispatcher </ servlet-name> <url-pattern> / dispatcher </ url-pattern> </ servlet-mapping></p> <p><taglib> <taglib-uri> / mytaglib </ taglib-uri> <taglib-location> /web-inf/mytaglib.tld </ taglib-location> </ taglib></p> <p></ web-app> 4. <? XML Version = "1.0" eNCoding = "ISO-8859-1"?> <! doctype taglib public "- // sun microsystems, Inc.//dtd jsp tag library 1.1 // En "" http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd "></p> <p><! - a tag library descriptor -> <taglib> <tlibversion> 1.0 </ tlibversion> <jspition> 1.1 </ jspition> <shortname> mytaglib </ shortname> <uri> / mytaglib </ uri></p> <p><tag> <name> Hello </ name> <tagclass> mypack.hellotag </ tagclass> <bodycontent> EMPTY </ bodycontent> <info> Just Says Hello </ info> </ tag></p> <p></ taglib></p> <p>◎ Compiling servlets need to add servlet-api.jarjidi to ClassPath: Process Context.lookup () -> DataSource.getConnection () -> Connection-> preplestatement () and to perform the necessary configuration in accordance with the step: 1 Configure server.xml2. Configure web.xml-> 1. <! - configure datasource. Add the folowing code in server.xml -></p> <p><Context path = "/ bookstore" docbase = "bookstore" debug = "0" reloadable = "true"></p> <p><Resource Name = "JDBC / BOOKDB" Auth = "Container" type = "javax.sql.datasource" /></p> <p><ResourceParams Name = "JDBC / BookDB"> <parameter> <name> factory </ name> <value> org.apache.commons.dbcp.basicDataSourceFactory </ value> </ parameter></p> <p><-!.. Maximum number of dB connections in pool Make sure you configure your mysqld max_connections large enough to handle all of your db connections Set to 0 for no limit -.> <Parameter> <name> maxActive </ name> <value> 100 </ value> </ parameter></p> <p><! - Maximum Number of iDLE DB Connections To Retain In Pool. Set to 0 for no limit. -> <parameter> <name> maxidle </ name> <value> 30 </ value> </ parameter> <! - Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds An Exception is thrown if this timeout is exceeded Set to -1 to wait indefinitely Maximum time to wait for a dB connection to become... Available IN MS, IN This Excetion Is Thrown if this timeout is excseded. set to -1 to wait indefinitely. -> <parameter> <name> maxWait </ name> <value> 10000 </ value> </ parameter></p> <p><! - MySQL DB Username and Password for DB Connections -> <Parameter> <name> UserName </ name> <value> dbuser </ value> </ parameter> <parameter> <name> password </ name> < Value> 1234 </ value> </ parameter></p> <p><! - Class Name for mm.mysql jdbc driver -> <parameter> <name> driverclassname </ name> <value> com.mysql.jdbc.driver </ value> </ parameter></p> <p><-!.. The JDBC connection url for connecting to your MySQL dB The autoReconnect = true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection mysqld by default closes idle connections after 8 hours -> <parameter> <name> jdbc: mysql: // localhost: 3306 / bookdb? AutoreConnect = true </ value> </ parameter> </ resourceparams> </ context> > 2. <! - add the folload code insto <webapp> in Web.xml -></p> <p><Resource-Ref> <Description> DB Connection </ description> <res-ref-name> jdbc / bookdb </ res-ref-name> <res-type> javax.sql.datasource </ res-type> <res -AUTH> Container </ res-auth> </ resource-ref></p> <p>3. Source file instance: <! - First import some necessary packages -> <% @ page import = "java.io. *"%> <% @ Page import = "java.util. *"%> < % @ page import = "java.sql. *"%> <% @ page import = "javax.sql. *"%> <% @ page import = "javax.naming. *"%> <% @ Page Import = "com.mysql.jdbc.connection"%> <! - Set Chinese Output -> <% @ page contenttype = "text / html; charset = GB2312"%> <html> <head> <title> dbjsp1.jsp </ Title> </ head> <body> <% // Try {java.sql.connection con; statement stmt; result</p> <p>// Establish a database connection Context CTX = new initialContext (); DataSource DS = (DataSource) CTX.lookup ("java: comp / env / jdbc / bookdb); con = ds.getConnection (); // Create a JDBC declaration STMT = con.createstatement (); // Add new record stmt.executeUpdate ("INSERT INTO BOOKS (ID, Name, Title, Price) VALUES ('999', 'Tom', 'Tomcat Bible', 44.5)"); // Query RS = Stmt.executeQuery ("SELECT ID, NAME, TITLE, Price from Books"); // Output Query Result Out.println ("<Table Border = 1 Width = 400>"); while (RS. NEXT ()) {string col1 = rs.getstring (1); string col2 = rs.getstring (2); string col3 = rs.getstring (3); float col4 = rs.getfloat (4); // Convert Character EnCodingCol1 = New String ("ISO-8859-1"), "GB2312"); col2 = new string (Col2.getbytes ("ISO-8859-1"), "GB2312"); col3 = new string COL3.GETBYTES ("ISO-8859-1"), "GB2312");</p> <p>// Print the data displayed out.println ("<tr> <td>" "</ td> <TD>" COL2 "</ TD> <TD>" COL3 "</ TD> <TD > " COL4 " </ TD> </ TR>);} out.println ("</ table>");</p> <p>// Remove the newly added record stmt.executeUpdate ("delete from books where id = '999");</p> <p>// Turn off the database link rs.close (); stmt.close () ;con.close ();</p> <p>// Capture the error message catch (Exception E) {Out.println (E.getMessage ());}</p> <p>%> </ body> </ html> ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p> <p>--------------------------------- {◎ How to set DNS, perform virtual host configuration ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎ ◎</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-59676.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="59676" 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.036</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 = '_2BGe_2BL91wjY3YiUCo_2BnuBe7LAcl_2FhYzWH8WlG7aADMvYWeUEZNcSzEqCYGUUcZEYlJc7kXXY0acJKSlpAUbG_2BGQ_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>