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.
• 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
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.
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.
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
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.
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.
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
(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:
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 ("
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.
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.
Web.xml: Initialization parameters can be in a servlet to: string value = getServletConfig (). GetInitParameter ("name"); ->