◎ 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"%>
web-app> 4. XML Version = "1.0" eNCoding = "ISO-8859-1"?>
taglib>
◎ 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.
<-!.. 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 -.>
<-!.. 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 ->
3. Source file instance: <% @ 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"%> <% @ page contenttype = "text / html; charset = GB2312"%>
// 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 ("