JSP Advanced Programming 3

zhaozj2021-02-08  229

Chapter 3 Establishment of JSP Development Platform: Tomcat has introduced a wide range of J S P engines since J S P released. As the world's useful WE B server software -a p a c h e is also practical research on J S P. The initial software product is G N u J S P implemented on the basis of A P a C H e J RT, which is G N u J s p1. 0, basically achieved JSP 1.0 standard. Another product called G s P is also appeared, which is achieved as a server-side of a server-side of the G N u system. Gnujsp is basically an attache of a Pache JS ERV. It mainly uses s ervlet to translate the JSP source file into a s Ervlet's J ava language source file, and then perform it as a s ervlet after compiling the J ava compiler, doing this Benefits have been explained before. After completing the development of G N u j s p1. 0, members of the development group began to consider developing a J S P server that can directly provide WE B services based on the J s W D k, of course, while also supporting S E R V L E T. In this way, J a K a R t a - to m c a t is born. As an open source software, J a k A r t a - to m c A T has its own unique advantage: First, it is easy to get. In fact, anyone can freely from the Internet. Regardless from H t t p: / / / j a k a r t a. A P a c h e. O RG or from other websites. Second, for developers, especially J ava developers, To McAT provides all source code, including the SERVLET engine, JSP engine, HTTP server......, Whether is interested in which aspect You can get your income from these code written by the world's top programmers. Finally, due to the opening of the source code and the fruitful work of many of the world's programmers, TO M C A T has been working with most mainstream servers, and works with considerable efficiency. Such as: in the form of a module is loaded into a P a c h e, which is loaded in I I S or P W S in the form of I S A P i, which is loaded into Netscape Enterprise Server in the form of N S A P i..... Next, the reader can see: • How to install To M C A t to make it work. • How to make TO M C A T and A P A C H E, I I S, etc. work. • How to configure to m c a t to meet your own requirements. Below, first establish a trialful J S P page, the reader can save the following code to HE E L O WO R L D. J S P.

JSP test page --- HelloWorld! </ Title> </ head> <body> <% out.println ("<H1> Hello World! <br> World, Hello! < /H11 "" "; "(/body>" (/HTML>3.1 To MCAT installation and directly using the home page of the Jakarta project of a Pache, you can see the TO MCAT's super connection, here you can find a variety of Version area, including the current release version, various versions in development, which are divided into Wi N 3 2 versions and L Inux versions, in fact for the To McAT, Wi N 3 2, which is written by J Ava The version and the L INUX version do not differ, such as the L INUX version, there is no problem under S Olaris. Here, it is mainly used as an example in Wi N 3 2. Note: Before installing to m c a t, first install J D K, preferably the J D k 1. 2. 2 or J D k 1. 3, S u n. First, J a k A R t a - t o m c a t. Z i p packet, unzipped into a directory, such as "C: / T O m C A T". At this time, you will get the following directory structure: Tomca Tomca Tomca Tomcat | - - - BIN TO MCAT Execute Script Directory | - - - Conf to McAT Profile | - - - DOC TO MCAT Documentation | - - - LIB To mcat running required library file (JARS) | - - log files for execution of Logs to McAT | - - - SRC To McAT Source Code | - - WebApps To McT's Major WE B Release Directory | - - Work To McAT's Work Contents, To McAT will translate the JSP file JSP file JAVA file and the class file here in the b in directory, there is a script file called Startup. BAT, you can start this script file, you can start TO MCAT Server, however, some settings are needed before starting the server. First, set the environment variable. Wi N 9 X uses a set statement in A U t o e c. B A T, such as: Set T O m c at_home = C: / Tomcat. In WinNT / Win 2 0 0 0, you can choose "My Computer", right-click the menu, select Properties, pop up the dialog "System Features", select the Advanced option page, then click "Environment Variable", you can edit The environment variable of the system. • To MC AT _ Home Value: C: / Tomcat (with to MC AT _ Home Indicates Tomcat Root Catalog. • Java_ Home Value: C: / Java / JDK (with J Ava _ Home Indicates JDK 1. 3 Installation Directory) .</p> <p>• Classpat h value: C: / J a V A / J D k / L i b / t o l s. J a r. In fact, the T O m c A T. B A t file can be directly opened for C L A S s Pat H, and can find several lines of S e TC L a s s pat h................................................................................................................................................................................................................................................ In addition, for JDK 1. 3, after installing on the Chinese system, the system registration table will have a problem. Use regedit to open the registration sector Javasoft, where is hkey_local_machine -> Software -> javasoft ->, find the "Java runtime environment" Export it to file Temp. Reg..... Similarly, it is best to replicate a "Java plug-in" in the J a V A S O F t registry key to "Java Plug-IN". Next, TO M C AT _ H O M E / B I N / S T A R T U P. B A T can be performed, and the TO M c A T is normal. Run a WE B browser such as Netscape Navigator or Internet Explorer. Type: h t t p: / / / 1 2 7. 0. 0. 1: 8 0 8 0. If you see the information of To M C A T, then the To M C A T has been installed successfully. Then test whether the J s P engine of To M c A t is working properly, the HE E L O WO R L D, which is established in front, is copied to TO M c at _ H o M E / W78 first part of JSP Getting Started</p> <p>In the eBAPPS / Examples / JSP directory, type: http: / / 1 2 7. 0. 0. 1: 8 0 8 0 / Examples / JSP / H Ello Wo RLD. JSP, this time You should be able to see the screen shown in Figure 3 - 1: Figure 3 - 1 In the process of starting to MCAT, some problems may be encountered, here are some instructions on common issues. 1) Start to M c A t fails. In this case, there may be two phenomena: The first: performs S t a r t u p. B A T does not appear in the JA V A window. The second: There is a JA V A window, but then exit itself. For the first case, it is probably that the To m c at _ h o m E environment variable is set, open the S t a r t u p. B A t file, observe the writing of the script, generally discoverable. For the second case, it may be that one server already has an 8 0 80 port in the current system. At this time, the original server is turned off, or the service port of TO M C A T is modified using the configuration method of TO M C A T will be used. It may also be due to the incorrect C L A S s Pat H, and if you need to check if C L A S s Pat H is set correctly. 2) Starting to m c a t success, you can see the home page, but you cannot perform J S P scripts. This is generally because Class Pat H is set to incorrectly or J ava _ home settings, and after experiments, when using Wi NDOWS, Java. EXE (C: / WinNT / SYSTEM 3 2 or C: / WINDOWS / This problem may occur when system). 3.2 TO MCAT and A Pache as a sub-project JAKARTA - Tomcat, as a Pache, is of course to provide strong support for A Pache, the establishment of the JSP development platform: To MCA T79 TO MCAT compression package There is a Tomcat - a pache. Conf file in the To McAGT _ Home / Conf directory, this file is not to McAT own profile, but is provided to a pache to make TO MCAT to work with A Pache. In fact, this file is automatically generated during the operation of TO M C A T. However, this file does not work together with the A Pache and To McAT, and a Dynamic Library file A Pache M Odule JS ER V. DLL can also be in the website http: / / jakarta. A Pache. O RG is obtained, it is necessary to explain that for the L INUX version of Tomcat, the MOD _ JSER V. SO file is required, and the file for the WS 5 0 is the dynamic link file file under L INUX. First, get the Apache HTTP server.</p> <p>A Pache is a free and providing source code HTTP server. Because A Pache's powerful performance and users can use the source code to construct their own HTTP server features, A Pache and its derived products have become the world's most application HTTP server. Even the IBM HTTP Server provided by the famous IBM company's We bsphere application server is also transformed by a pache. At http: / / jakarta. A pache. O RG can get the latest version of the A Pache server, when writing, the latest release has arrived at a pache1. 3. 1 2, and a pache 2. 0 A 6 It has also been provided for testing. Wi N D O W S's a P a C H e version is an installation file that can be easily installed on your computer. And if A P A C H e is used in L i n u x, it is best to use the source code package to compile themselves. It should be noted that the option E n a B L E -M O D U L E = S O is required when compiling. Double-click A P A C H E _ 1 _ 3 _ 1 2 _ Wi N 3 2. E X E file for installation, the default installation directory is C: / Program Files / Apacheg R o U P / A P A c h e, you can modify the directory you like. If you need to modify the port number of the A P A C H E server works and the H T M L publishing the directory or other A P A C HE parameters, then a P a c h e mounting directory / C O N f / h t t p d. C O N f, which typically modifies the H t ml publishing the directory for your own directory. As for the port number, when there are other WE B servers on the computer, it can be modified, and if the PWS is installed, if PWS is installed, IIS is installed on the machine of Wi NDOWS NT and Windows 2000. It also needs to be modified. For machines that are not connected to the network, sometimes set S E R v E R n a m e. The specific configuration of a P a c h e server is referred to, and you will not talk about it. Alternatively, A P A C H E is installed on a computer running Wi N D O W s N T and Windows 2000 as a service. This only needs to perform the start → program → Apache Web Server → Install Apache as a service. Open the browser and type http: / / 1 2 7. 0. 0. 1: a pache in the address bar, if you can see a Pache welcome page, or a lot of files let you choose, You can think that a Pache server has already started working. After the Apache HTTP server is configured, you can work together to work with the To M C A T and A P A C HE.</p> <p>First, the obtained A Pache M odule js er v. DLL file is copied to the modules subdirectory in the A Pache installation directory, and the user of l INUX copies the MOD _ JSER V. SO file to the libexec directory of the A Pache installation directory. Then, then the HTTPD in the A Pache installation directory is opened with a text editor, and the following instructions are added below: include to mcat _ h ome / confidence to mcat. Conf - for Wi NDOWS users. Or include to m c a t_ h o m E / C O N f / t o m c a t. C O N f - for the L i N u user. The above TO M c A T_H refers to the installation directory of To m c a t. Finally, in the H t t p d. C O N f file plus a line: loadModule jserv_module modules / apachemodulejserv.d l. 80 Part 1 JSP Getting Started</p> <p>For users under L i n u x, do not need to manually add loadModule jserv_module libexec / mod_jserv. S O this line, T o m c A T - a p A c h e. C o n f file has been default, if not add, you can add itself. After everything, restart a Pache server and to McAT, type in the address bar of the browser: http: / / / 1 2 7. 0. 0. 1: a pache running port number / examples / jsp / if See the list of To Mcat's JSP sample, you will explain to McAT has worked with a pache. 3.3 TO MCAT and IIS The most common WE B server under the Wi NDOWS platform is undoubtedly IIS (including PWS). For IIS, TO MCAT also provides methods of cooperating with work, using this method, you can do not have Java servlet And JSP function IIS increases the functionality of JSP and J avly. In order to work together with the to McAT and IIS, you must get ISAPI _ Redirect. DLL, this is an IIS plugin (P Lug - IN), which can be compiled from http: / / jakarta. A pache. O RG / directly compile You can also compile it yourself with Visual C . After getting it, put it in your favorite directory, such as C: / Tomcat / Jakarta-Tomcat / Bin / IIS / I386 / directory. In addition, during the process of mating I I S and TO M C A T, the configuration file of the other two TO M c A T is also required, one is W O R k E R s. P R O P E R T I e s, which defines the host and port used by the working process of TO M C A t. There is an exemplary W O R K E R S. P R O P E R T I E E S file in the C O N f directory of TO M C A T. The other is U R I W O R K E R M A P. P R O P E R T I E E S, this file is a map of the U r L directory and the TO M c A T work process. Similarly, there is an exemplary U R I W O R K E R M A P. P R OP E R T I E E S. First, configure I S A P i _ R E D I R E C T. D L. 1) Create a new key value in the system registry: HKEY _ local _ Machine / Soft Wa RE / A PACH ESOFTWARE FOUNDATION / JAKARTA Isapi Redirector / 1.0.2) Add a string value named Extension _ URI is / JAKARTA / ISAPI _ Redirect. DLL. 3) Add a string value called L O g_ f i l E C: / T O m C A T / J a K A R T A - T O m C A T / L O g S / I S A P i. L o g.</p> <p>4) Add one of the string values ​​called L O g_l E V E L as D E B U G, I N f O R M, E R R O R, E M E RG. 5) Add a string value named W o R k e r _ f i l e is 6) c: /tomcat/jakarta-tomcat/conf/Workers.properties. 7) Add a string value called W o R k e r _ M o U N t _ f i l E) C: / Tomcat / Jakarta-Tomcat / conf / uriworkermap.properties. Then, open the management console of I I S and add a virtual directory to the Web site of the JS P and Java Servlet services using TO M C A T. Note, be sure to use "Jakarta" as the name of the virtual directory, the actual physical location of this virtual directory should include the directory of the ISAPI _ Redirect. DLL file, here is assumed to be C: / Tomcat / J Akarta - Tomcat / Bin / IIS / i 3 8 6. Note that this virtual directory is executable when setting the virtual directory. If it is in P W s, the same processes. Next, add an I S A P i filter to this WE B site in the console of I S (right-click on this WE B). The name is free, but the filter is to be set to I S A P i _ R e D i R E C T. D L1 this file. If P w s is used, it is more troublesome. Need to use a registry editor, in the key HKEY _ LOCAL _ MACHINE / S YSTEM / C URRENT C Ontrol S etc / s er valles / w 3 SVC / P Arameters, there is a key value called Filter DLLS in this key. Add ISAPI _ Redirect. DLL in the value, pay attention to the full path. Chapter 3 JS P Development Platform Establishment: To M C A T81 Finally, restart I I S or P W S, preferably to restart the computer. After starting To McAT, open the browser, type http: / / 1 2 7. 0. 0. 1 / Examples /, if you can see both the JSP and Servlets, you can see the use of isapi _ redirect. Dll The redirected redirection has been successful and can perform an example of the example in the JSP directory. 3.4 TO MCAT Configuration and FAQ To McAT provides users with a range of configuration files to help users have different to mcats, and apache http, to MCAT configuration files are primarily based on XML; such as serve r. XML, Web. Xml........................................... This section will discuss in detail the main profile of To M C A T and how to use these configuration files to solve common problems. 3.4.1 Main Profile of To M C A T: S E R V E R. X m L Observation S E R V E R. X M L, which can be found in some elements such as Table 0.</p> <p>Table 3 - 1 Element Description S E R V E R is the SE R V E R Element is the highest level of the highest level of the X M L file, and the S e R v E R element describes a TO M c A T server, generally the user does not care about this element. One S e R v E R element generally includes L O g g E R and C O N t e x T m a n g e r two elements L O g g E R is the L O g g E R element defines a log object, and a log object contains the following attribute: Yes 1) Name. Represents the name of this log object. Yes 2) path. Indicates which log files are to be output to this log object. Is 3) V e r b O s I t y L e v E L. Represents the level of the log of this log file record. In general, the L Ogger object is a record of Java Servlet, JSP, and To McAT running period. C ontext m Anager is C ontext m Anager defines a set of C ontext I NTERCEPTORS (c ontext m anage event listener), Requestinterceptors (C ontext M Anage Event Loys), C ontexts (context directory of WE B applications) and their C Onnectors (connectors) structure and configuration. It is C O N t e x t m a n a g e r contains some properties: Yes 1) Debug. Record the level of the log record debugging information. Is 2) home. W E B A P P S /, C O N f /, L O g S / and all CO N t e x T 's root directory information. This property is to start TO M C A t from a directory that is different from to m c at _ H O M e. 3) WORKDIR. TO M c A T works directory. ContextInterceptor and R e q u e s T I N T E R C E P T O R are interceptors that listen to a particular event of C O N T E X T M a N A g E R. C O N t e x T I N t e R C E P T O R Acts the start and end event information of TO M C A T. RE Q u e s t i n t e r c e p t o r monitors the request information sent by the user to the server. General users do not need to care about these interceptors. For developers, it is necessary to understand that the method of global operation is implemented. C onnector is a C Onnector (Connector) object describing a connection to the user, whether it is direct by TO MCAT to the user The browser is still passed through a WE B server. The working process of TO M c A t and the read / write information and request / reply information generated by different users are managed by the connector object. In the configuration of the connector object, you should include the management class, T C P / I P port, etc. 82 first part JSP entry</p> <p>(Continued) Element Description C O N t e x T is that each C O N t e x T describes a directory of the WE B application of TO M c A t. This object contains the following properties: Yes 1) DOCBASE. This is the directory of C O N t e x t. It can be an absolute directory or a relative directory based on the root directory of C O N T E X T m a N A g e. Yes 2) path. This is the virtual directory location and directory name when C O N T E X T at WE B service. Yes 3) Debug. The debug information recording level of the log record. Is 4) Reloadable. This is to facilitate the SERVLET developer, when this property switch is turned on, to McAT will check if the SERVET is updated and decide whether it is automatically reload it 1. Add your log file to add the L Ogger object You can add your own log file, adding a job is quite simple, just copy one of the L Ogger objects as an example, and then modify the few properties described above. After setting L O g g e r, S E R V L E T C O N TEx. L O g () method can be used to establish its own log files in its own SE R V1. 2. Setting the new J S P directory to set up a new J S P work directory is relatively simple, just add a C O N t e x T object. For example, to develop JSP items in the C: / JSP directory, and let users access to / mybook / virtual directory, then: <context path = "/ mybook" DOCBASE = "C: / JSP" debug = "0" Reloadable = "True"> </ context> Generally, the JSP file can be executed directly. If further I want to establish a WE B application below, then further configuration, the specific method is discussed later. 3.4.2 Wi NDOWS Code Protection Questions When using To Mcat under Wi NDOWS, there is a problem. You need to pay attention. After you can do a test, you can type in the address bar of your browser: http://127.0.0.1 : 8080 / Examples / JSP / HELLOWO RLD. JSP (note the suffix to capitalize). Just find that the strange phenomenon, there is nothing in the browser window, see the H tml source file will find that the source code of this J S P file is fully output to the browser! If so, isn't any source code of the server side, it will be exposed on the Internet. In fact, the solution is simple, write all the combinations of various suffixes to the to mcat _ h ome / conf / web. In XML, this Tomcat will be treated separately from the JSP of different retries, will not disclose the code. .</p> <p><servlet-mapping> <servlet-name> jsp </ servlet-name> <url-pattern> *. jsp </ url-pattern> </ servlet-maping> <servlet-maping> Chapter 3 JSP development platform establishment : TO MCA T83 <servlet-name> jsp </ servlet-name> <url-pattern> *. Jsp </ url-pattern> </ servlet-mapping> <servlet-maping> <servlet-name> jsp </ servlet -name> <url-pattern> *. jsp </ url-pattern> </ servlet-mapping> <servlet-maping> <servlet-name> jsp </ servlet-name> <url-pattern> *. jsp </ URL-PATTERN> </ servlet-mapping> <servlet-maping> <servlet-name> jsp </ servlet-name> <url-pattern> *. jsp </ url-pattern> </ servlet-mapping> <servlet- Mapping> <servlet-name> jsp </ server-name> <url-pattern> *. jsp </ url-pattern> </ servlet-maping> <servlet-maping> <servlet-name> jsp </ servlet-name > <url-pattern> *. JSP </ url-pattern> </ servlet-mapping> <servlet-maping> 84 Part 1 JSP Getting Started</p> <p><servlet-name> JSP </ servlet-name> <url-pattern> *. JSP </ url-pattern> </ servlet-maping> 3.4.3 Apache, IIS and TO MCAT Collaboration Time Directory Add 1. Apache Since the J Akarta-To McAT project is a sub-project of a Pache, you only need to modify the To McAT - a pache. Conf files when adding a working directory to the WE B server collaboration with To McAT - A Pache. Perhaps the reader will feel strange, to m c A T -A P A c h e. Is the C O N F Automatically generated when TO M c A T is started? It is true, but to mcat automatically generates to mcat -a pache. Conf file is only a default profile provided by To McAT, if needed, you can modify, then store it in another directory, or change the name, then This new file is included in the HTTPD. conf file. Why does the To m c A T do not automatically modify the need for TO M C A T - A P A C H E. C O N F to accommodate the need to add a job directory? To m c A T did modify the To M C A T - a P A C H E. C O N F file, but the modified results are obviously incorrect. For example, add a working directory / mybook - -> C: / JSP, to McAT-A Pache. Conf files, add this a few lines, add such lines: Alias ​​/ MyBook C: / Tomcat / jakarta-tomcat / webapps / mybook <Directory "C: / tomcat / jakarta-tomcat / webapps / mybook"> Options Indexes FollowSymLinks </ Directory> ApJServMount / mybook / servlet / mybook <Location / mybook / Web-INF /> AllowOverride Nondeny From all </ location> This is obviously problematic, although the virtual directory is / MyBook, but the actual directory is not C: / Tomcat / Jakarta -tomcat / WebApps / MyBook.</p> <p>View to McAT source code C: / Tomcat / Jakarta - Tomcat / src / o RG / A Pache / Tomcat / Task / a pache c onfig. Java files can be found, to mcat is generating to mcat - a pache. Conf file Time, simply add the default WebApp directory of the original To McAT as a new work directory in front of the virtual directory: PW.Println ("Alias" PATH " FileUtil.Patch (Tomcathome " / WebApps " PATH) ); PW.Println ("<Directory /" FileUTil.Patch (Tomcathome "/ WebAPPS" PATH) "/"> "); PW.Println (" Options Indexes Followsymlinks); PW.Println (" </ Directory> "); So how to solve this problem? Modify the source code of TO M C A T can also, but for a general user, the TO M c A T - a P A c h e. C O N f file is more realistic. Modified methods are as follows: Alias ​​/ MyBook C: / JSP Chapter 3 JSP Development Platform Establishment: To MCA T85 <Directory "C: / JSP"> Options INDEES FOLLOWSYMLINKS </ DIRECTORY> APJSERVMOUNT / MyBook / Servlet / MyBook <location / mybook / web-inf /> allowoverride nonedeny from all </ location> is simply incorrect C: / Tomcat / Jakarta - Tomcat / WebApps / MyBook modified to C: / JSP. After modifying the file, you must save another file and modify the httpd. Conf file contains this file into in, otherwise, after restarting To McAT, this correct to McAT - a pache. Conf file will be regenerated by TO MCAT To mcat -a pache. The conf file is overwritten. Finally, restart A p A c h e and to m c a t is OK. 2. IIS is different from which almost seamless cooperation with A P a C H E and TO m C A T, I I S and TO M C A T are somewhat complicated, and new content is added to ISAPI Redirect. However, it is ok, the U N I W O R K E R M A P in TO M C A T is simplified in this process. Things you need to do are divided into two steps: 1) Add a working directory to To M C A T. The previous example has been described above, which is still using / m y b o o k - -> c: / j s. 2) Add a working directory to ISAPI Redirect.</p> <p>Use the text editor to open the file U n i w o R k E R m a p. C o n f, add a line: / mybook / * = AJP12 and then restart I I s and to m c a t. 3.4.4 Setting To McAT As a service of Wi NDOWS, start manual boot to McAT is clearly not a suitable method of using to mcat as a WE B service. You can automatically start TO MCAT by modifying startup scripts under L Inux, in Wi NDOWS The following can be set to set to MCAT as a service of Wi NDOWS. TO M C A T serves as a service of Windows NT / 2000 is a tool that needs to be taken by means of a tool. The URL is H t t p: / / / / / / / / / / / / / / / w. A D V O K. C O m / g S E R V A N Y. H T M L. Unzip the z I p file and place G S e R V a N y. E x E in the W i N N T / S Y S TEE M 3 2 directory (in order to be accidentally deleted). 2) Enter the c o m m a n d (command line mode) of N t: gserve -i Tomcat "C: / J a K a R TOMCAT" C: / J A K a R Tomcat "C: / b I n" "S t a R T u p. B A T" C: / J A R T A - T O m C A T / B I n "" S H U T D O w n. B A T ". 3) Start S E R V I C E Manager, you will see Tomcat Service, add some comments, this S E R V i c e actually does it, and then modify the start type "Auto". Then start it. In this way, TO M C A T is successfully installed in N t as S e R v i c e. In fact, there is still a lot of tools that use applications under N t as a service in N t, and any one should be able to get 86 first part of JSP.</p> <p>TO M C A T is added to the N t service. 3.4.5 Creating a new WE B application in To McAT JSP is primarily developed to establish a Web site, this technology is a complete set of WE B files (JSP, Servlet, HTML, JPG, " GIF, Class.......... To m c a t provides a range of help for the establishment of WE B applications, the following steps are described. 1. The directory and structure of the application follows the specification of To M C A T, from the / e x a m pl example directory, the WE B application of TO M C A T should consist of the directory shown in Table 3 - 2. Table 3 - 2 * .html, * .jsp, etc. This can have many directories, depending on the user's website structure, the implementation function should be the interface of the website, that is, the main visible part of the user. In addition to the HTML file, JSP file, there are JS (J Ava S cript) files and CSS (style sheets) files, and other multimedia files, etc. WE B - INF / Web. XML This is a description file for a WE B application . This file is an XML file that describes the other component information of the SERVLET and this WE B application, and some of the initialization information and security constraints, etc. WE B - INF / CLASSES / this directory and the subdirectories should be All SERVLET files including this WE B application, and other Class files and related resources that are not compressed into the JAR package. Note that the J a V A in this directory should contain all the class files and related files compressed into the J A R file according to the package organizational directory WE B - I N F / L I b / this directory. For example, the third party provides the J a V library file, J D b C driver, etc. in the third party........... Web.xml file W e b. X ml file contains information describing the entire Web application. The following is taken as an example of a W e b. X m l file, explain the individual objects inside.</p> <p>Web.xml: <! doctype web-app public "- // sun microsystems, Inc.//dtd web application 2.2 // en" http://java.sun.com/j2ee/dtds/web-app_2_2.dtd "> <web-app> The main description of the <! <display-name> my web application </ display-name> <design> Add to Web Application Description Information </ description> < ! > Chapter 3 JSP Development Platform Establishment: To MCA T87 <Context-Param> <param-name> Webmaster </ param-name> <param-value> myaddress@mycompany.com </ param-value> <design> Here Description of the initialization parameters </ description> </ context-param> <! - The following definition describes the servlet that makes up this web application, and also includes initialization parameters. In Tomcat, you can also access the servlets in web-inf / classes to servlet / servlet names, but in general, it is not recommended to use this. And this method can also result in the complexity of the relevant resource organization of the servlet. Therefore, it is generally recommended to define all servlets here.</p> <p>Initialization parameters can be in a servlet to: string value = getServletConfig (). GetInitParameter ("name"); -> <servlet> <servlet-name> controller </ servlet-name> <design>> here Description of this servlet </ description> <servlet-class> com.mycompany.mypackage.controllerServlet </ servlet-class> <init-param> <param-name> listorders </ paramname> <param-value> com.mycompany. MyActions.ListorderDersAction </ param-value> </ init-param> <init-param> <param-name> Savecustomer </ paramname> <param-value> com.mycompany.myactions.savecustomraction </ param-value> </ INIT-PARAM> <! - During the server starts this servlet loading time-> <load-on-startup> 5 </ load-on-startup> </ servlet> <servlet> <servlet-name> graph </ servlet -Name> <description> This Servlet Description </ description> </ servlet> <! - servlet mapping corresponds to a special URI request to a special servlet relationship -> 88 Part 1 JSP Getting Started</p> <p><servlet-mapping> <servlet-name> controller </ servlet-name> <url-pattern> *. do </ url-pattern> </ servlet-mapping> <servlet-maping> <servlet-name> graph </ servlet-name> <url-pattern> / graph </ url-pattern> </ servlet-mapping> <! - Set the default session expiration time -> <session-config> <session-timeout> 30 </ Session-Timeout> <! - 30 minutes -> </ session-config> </ web-app> 3. Packaging the application as a way to wE B applications, use WA R files are convenient to manage various related documents, and reduce the volume of the entire application. Let's take a look at the grammar to package the WE B application as WA R file: packager -Webarchive [-classpath servletorjspbean / class [-classfiles package / myclass1.class: package / myclass2.class] <content-root> [ -contentFiles login.jsp: index.html: images / me.gif] Web.xml MyWebapp.war The following is a simple application example, the configuration of My We B P Age. XML, MY WE B P AGE D IR / the package file into my We b P age war in:. packager -webArchive myWebPageDir myWebPage.xml myWebPage.war use -contentFiles logo can add individual catalog file packager -webArchive myWebPageDir -contentFiles Hello.jspmyWebPage.xml myWebPage.warpackager -webArchive myWebPageDir -contentFiles Hello.jsp: Hello.htmlmyWebPage.xml myWebPage.war assume S ervlet file classes / package / S ervlet 1 class, designated S ervlet and JSP files:. packager -webArchive -classpath classes myWebPageDir -contentFilesHello.jsp myWebPage. . xml myWebPage.war contains only the following example of how the package / Servlet1.class and packageB / Servlet.class WA R files into two files: packager -webArchive -classpath classes -classFiles package / Servlet1.class: packageB / Servlet.class myWebPageDir -Contentfi Leshello.jsp mywebpage.xml mywebpage.war, the final, it is necessary to explain, each. W a r file, front. x ml file is the W e b. x ml file. The generated WA R file can be used directly in a directory containing the WE B application.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-3345.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="3345" 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.033</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 = 'wNdeMZZrFOVxwUQO4Doit_2Fx4pbMj8BzWKplJuZ5pVsfNVg3mCOHFJNF0y_2FdfY6Tw9d9VHZfJSDjO4q8pn9DahQ_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>