1. Develop web applications 1.1 Use virtual path knowledge points: 1.1.1 (context name, copy directly to WebApps directory, directly access folder) 1.1.2 WAR: Web program compression package production: D: / Hello > JAR CVF Hello.war *. * Access: Copy Hello.war to WebApps Directory, restart Tomcat, discovery will automatically decompress EAR: 1.1.3 web.xml: xml version = "1.0" eNCoding = "ISO-8859- 1 "?>
mys servlet-name> // alias servlet> mys servlet-name> / myweb / myweb url-pattern> // Deployment Virtual Path servlet-maping> web-app> 1.1.4 modification of form form: action = "MyWeb / MyWeb "// Do not add /, otherwise the representative is the top-level directory 1.2 servlet lifecycle knowledge point: JBoss: EJB container WebLogic: EJB container and JSP, servlet container connection pool: init, service, destroy is the container automatic call , Generally do not need to be overloaded. 1.3 SERVLET Jump RequestDispatcher Rd = NULL; // Defines Variable Rd = Req.getRequestDispatcher ("/ CHN"); // Jump to another class RD.Forward (REQ, RES); // Pass two variables
1.4 ServletContext is understood as a global variable, can put database connections, improve access efficiency, and implement shared web.xml (must be placed in front) Define variable CName param -Name> GGYY param-value> context-param> InputNameToServlet.java Get variable servletcontext sc = getServletContext (); string cname = sc.getinitParameter ("cname"); 1.5 Using the web. Context-Param and StringTokenizer method in XML read and write text database Web.XML filename param-name> /web-inf/stud.txt param -value> context-param> ReadTxt.java in String filename = sc.getInitParameter ( "filename"); InputStream is = sc.getResourceAsStream (filename); BufferedReader br = new BufferedReader (new InputStreamReader (is)); while ( (s = br.readline ())! = null) {StringTokenizer St = New StringTokenizer (s); while (st.hasmoretoKens ()) {string ssn = st.nextToken (); string name = st.nextToken (); String sex = st.nextToken (); out.println ("" ssn "
" SSN TD>
" Name " TD>
" SEX " td> tr> ");}}
1.6 Using listen> in Web.xml to load the container to start and close, destroy certain objects. 1.7 Using Session Management 1.7.1 Using Cookie 1.7.2 Use URL to override
Homework: Do a JSP message this to use Strus for MVC development information (no Java code in view, using JSP custom label)