JSP Development Environment Configuration L Series ---- Tomcat

zhaozj2021-02-16  88

Establishment of JSP Development Platform: Tomcat

As an open source software, Jakarta-Tomcat has its own unique advantage: First, it is easy to get. Second, for developers, especially Java developers, Tomcat provides all source code, including servlet engines, JSP engines, HTTP servers....., No matter which length, you can Get your income from these codes 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, Tomcat has been able to work with most of the mainstream servers, and work with considerable efficiency. For example, in the form of a module is loaded into the Apache, ISAPI is loaded in the form of ISAPI, which is loaded into Netscape Enterprise Server in the form of NSAPI......

Next, we do:

• How to install Tomcat to make it play.

• How to make Tomcat and Apache, IIS, etc. work.

• How to configure Tomcat to meet your requirements.

Below, let's create a trialful JSP page, first save the following code as helloworld.jsp

JSP test page --- HelloWorld! </ Title></p> <p></ HEAD></p> <p><Body></p> <p><%</p> <p>Out.println ("<H1> Hello World! <br> World, Hello! </ h1>");</p> <p>%></p> <p></ Body></p> <p></ Html></p> <p>Tomcat installation and direct use</p> <p>On the homepage of Apache's Jakarta project (http://jakarta.apache.org/), you can see Tomcat's super pick, here (http://jakarta.apache.org/tomcat/index.html) Find a variety of download area, including the current release version, various versions in the development, which is divided into Win 32 version and Linux version, in fact, for Tomcat, Win 32 and Linux version written by Java There is not much difference, such as the Linux version, there is no problem under Solaris. Here, it is mainly used as an example in WIN 32.</p> <p>Note: Before installing Tomcat, install JDK first, preferably Sun's JDK 1.4 or JDK 1.5.</p> <p>First, download Jakarta-Tomcat .zip (the latest version of Tomcat 5.0 provides an EXE file, but the file directory after the installation is similar to the configuration is similar) packetization compression to a directory, such as "C: / Tomcat". At this time, you will get the following directory structure:</p> <p>Tomcat</p> <p>- - JAKARTA-TOMCAT</p> <p>| - - - BIN Tomcat Execute Script Directory</p> <p>| - - - Conf Tomcat Profile</p> <p>| - - - DOC Tomcat documentation</p> <p>| - - - LIB Tomcat runs the required library file (J a r s)</p> <p>| - - LOGS Tomcat executive L O g file</p> <p>| - - - SRC Tomcat source code</p> <p>| - - - WebApps Tomcat's main WE B Release Directory</p> <p>| - - Work Tomcat's working directory, Tomcat will translate the JSP file to the Java file and the class file here in the bin directory, there is a script file called Startup .bat (Tomcat 4, and previous version) This script file can start Tomcat servers, but some settings are required before starting the server. First, set the environment variable. Win 9X uses a set statement in AutoExec.bat to set the environment variable, such as: Set t o m c at_home = C: / Tomcat. In WinNT / Win2000, "My Computer" can be selected, right-click the menu, select Properties, pop up the dialog "System Features", select "Advanced" option page, then click "Environment Variable" to edit the environmental variable of the system .</p> <p>• Tomcat_home value: c: / tomcat (with Tomcat_home Indicates Tomcat root directory.)</p> <p>• Java_Home Value: C: / Java / JDK (Indicates the JAVA_HOME Indicates the JDK installation directory).</p> <p>• ClassPath value: c: /java/jdk/lib/tools.jar.</p> <p>In fact, for ClassPath, you can also open the tomcat.bat file directly, you can find a few lines of Set ClassPath in the middle.</p> <p>..., add yourself to the library file you want to join.</p> <p>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 selection javasoft, where is hkey_local_machine -> Software -> javasoft ->, find the "Java runtime environment" Export to the file temp.reg...., Then edit it with NOTEPAD, replace the "Java Runtime Environment" and then import. Again, it is best to copy a "Java plug-in" in the JavaSoft registry other to "Java Plug-in". Next, you can perform Tomcat_Home /bin/startup.bat, test whether Tomcat is operating normally. Run a WE B browser such as Netscape Navigator or Internet Explorer. Type in the address bar of the browser: http: // localhost: 8080. If you see Tomcat information, then Tomcat has been installed successfully. Then test whether Tomcat's JSP engine is working properly, and copies the Hellorld.jsp files created in front to the Tomcat_Home / WebApps / Examples / JSP directory, and then in the address bar of the browser: http: // localhost: 8080 / Examples / JSP / HelloWorld.jsp, this should be able to see the screen shown in Figure 3 - 1:</p> <p>Figure 3 - 1 (I don't grab the picture, "means the HelloWorld in the browser)</p> <p>In the process of starting Tomcat, some issues may be encountered, here are some instructions on common issues.</p> <p>1) Start Tomcat failed. There may be two phenomena when this happens.</p> <p>The first one: There is no Java window that appears after performing Startup.bat.</p> <p>The second: There is a Java window, but then yourself withdrawal.</p> <p>For the first case, it is likely that the Tomcat_Home environment variable is set, open the startup.bat file, observe the writing of the script, can generally find problems. For the second case, it may be that one server already has an 8080 port in the current system. At this time, it is necessary to turn off the original server or use the configuration method of the Tomcat described later. Modify Tomcat's service port. It may also be due to the incorrect ClassPath setting, then check if the classpath is set correctly. 2) Start Tomcat Success, you can see the home page, but you cannot perform JSP scripts.</p> <p>This is generally because the ClassPath setting is incorrect or the java_home is set, and after the experiment is found,</p> <p>This problem may occur when using Windows comes with Java.exe C: / Winnt / System32 or C: / Win D O W S / S Y S TEE M).</p> <p>Tomcat and Apache</p> <p>As a subproject as Apache, Jakarta-Tomcat, is of course providing powerful support. After the downloaded Tom Cat compressed package is unwrapped, there is a tomcat-apache.conf file in the tomcagt_home / conf directory, this file is not Tomcat Your own profile, but provide to apache to make Tomcat to work with Apache. In fact, this file is automatically generated during the running of Tomcat. However, the light has this file to work with the Apache and Tomcat, but also need an Apache's dynamic load file ApachemoduleJServ.dll, this file can also be obtained at the website http: //jakarta.apache.rg, need to explain For the Linux version of Tomcat, it is required to be mod_jserv.so files, and the file for the WS50 is the dynamic linkage file under Linux.</p> <p>First, get the Apache HTTP server. Apache is a free and providing source code HTTP server. Because Apache's powerful performance and users can use source code to construct your own HTTP server features, Apache and its derived products have become the world's most HTTP server, even The IBM HTTP Server provided by the famous IBM company's WebSphere application server is also transformed by Apache. At http://jakarta.apache.org, you can get the latest version of the Apache server. The Apache version under Windows is a installation file that can be easily installed on your computer. And if you use Apache under Linux, it is best to use the source package yourself to compile it yourself, you need to note that the option enablemodule = SO is required when compiling.</p> <p>Double-click Apache_1_3_12_win 32.exe file for installation, default installation directory is C: / program files / apache</p> <p>Group / Apache can be modified to your favorite directory. If you need to modify the port number of the Apache server and the HTML publishing directory or other Apache parameters, you can modify the Apache installation directory /conf/httpd.conf, usually modify the HTML publishing directory for your favorite directory. As for the port number, when there are other WE B servers on the computer, it is possible to modify if PWS is installed on the machine, and if IIS is installed on the machine of WindowsNT and Windows 2000, it is also necessary to modify it. For machines that are not connected to the network, sometimes set the concrete configuration of the ServerName.apache server, see the relevant books, this is not said.</p> <p>In addition, it is best to install Apache as a service on a computer running Windows. This only needs to perform the start → program → Apache Web Server → Install Apache as a service. Open the browser, type http: // localhost: Apache running in the address bar, if you can see the Apache welcome page, or a lot of files allow you to choose, you can think that the Apache server has started working. After the Apache HTTP server is configured, you can start working with the Tomcat and Apache. First, copy the obtained Apache modulejserv.dll file to the modules subdirectory in the Apache installation directory, linux users copy the mod_jserv.so file to the libexec directory of the Apache installation directory, then put the httpd.conf in the Apache installation directory The file is opened with the text editor, add the following instructions in the end: include tomcat_home / conf / tomcat.conf - For Windows users. Or include Tomcat_home / conf / tomcat.conf-for Linux users. The top of Tomcat_home refers to the installation directory of Tomcat. Finally, plus a line in the httpd.conf file: loadModule Jserve_Module Modules / ApachemoduleJServ.dll. For users under Linux, do not need to manually add loadModule jserv_module libexec / mod_jserv. S o this line, Tomcat-Apache.conf file has been default, if not, add itself. After everything is ready, restart the Apache server and Tomcat, type in the address bar of the browser:</p> <p>Http: // localhost: Apache Run port number / examples / jsp / if you can see the Tomcat's JSP sample list, you will explain that Tomcat has worked with Apache.</p> <p>Tomcat and IIS</p> <p>The most common web server under the Windows platform is undoubtedly IIS (including PWS). For IIS, Tomcat also provides a method of cooperating with work. Using this method, you can add JSP and JavaServlet for IIS that does not have Java servlet and JSP. Function. In order to work together with Tomcat and IIS, you must get Isapi_Redirect.dll, which is an IS plugin (Plug-in), you can download the compiled version from http://jakarta.apache.org/, you can also use it yourself Visual C is compiled. After getting it, put it in a directory you like, for example, C: / Tomcat / JakartAmcat / BIN / IIS / I386 / directory. In addition, during the process of making IIS and Tomcat, another two Tomcat configuration files are required, one is worker.properties, which defines the host and port used by Tomcat's working process. There is an exemplary workers.properties file in the Tomcat's confed. Another uriWorkermap.properties, this file is a map of the URL directory and Tomcat work processes. Similarly, there is an exemplary uriWorkerMap.properties in the CONF directory of Tomcat.</p> <p>file.</p> <p>First, configure ISAPI_Redirect.dll</p> <p>1) Create a new key value in the system registry: HKEY_LOCAL_MACHINE / SOFTWARE / APACHE</p> <p>Software Foundation / Jakarta Isapi Redirector / 1.0.2) Add a string value called Extension_uri to /jakarta/isapi_redirect.dll.</p> <p>3) Add a string value named log_file to c: /tomcat/jakarta-tomcat/logs/isapi.log.</p> <p>4) Add one of the string values ​​called log_level to debug, inform, error, and Emerge.</p> <p>5) Add a string value called Worker_File as</p> <p>6) c: /tomcat/jakarta-tomcat/conf/Workers.properties.</p> <p>7) Add a string value called worker_mount_file as</p> <p>8) C: / tomcat / jakarta-tomcat / conf / uriworkermap.properties.</p> <p>Then, open the IIS management console, add a virtual directory to the Web site that needs additional JSP and Java Servlet services you need to use Tomcat. Note that you must use "Jakarta" as the name of the virtual directory, the actual physical location of this virtual directory should be a directory containing the ISAPI_Redirect.dll file, here is assumed to be C: / Tomcat / JakartAmcat / Bin / IIS / I386. Note that this virtual directory is executable when setting the virtual directory. If it is in the PWS, it will be processed. Next, add an ISAPI filter to this web site in the IIS's console (right-click on this WE B site, select Properties). The name is free, but the filter is to be set to ISAPI_Redirect.dll this file. If you are using PWS, it is more troublesome. Need to use a registry editor, in the key hkey_local_machine / system / currentcontrolset / service / w3svc / parameters, there is a key value called filter dlls, add isapi_redirect.dll in this key value, and note that the full path is included. Finally, restart IIS or PWS, it is best to restart the computer. After starting Tomcat, open the browser, type http: // localhost / example / examples / if you can see the JSP and Servlets, you can perform the JSP, you can execute the JSP. Examples of the directory do test.</p> <p>Tomcat configuration and common problems</p> <p>Tomcat provides users with a range of profiles to help users have different Tomcats, and apache http, Tomcat's profile is primarily based on XML; such as server.xml, Web.xml ..., only workers A few files such as .properties and u riworkermap.properties are traditional configuration files. This section will discuss Tomcat's main configuration files and how to use these configuration files to solve frequently issues.</p> <p>Tomcat's primary configuration file: server.xml</p> <p>Observe Server.xml, you can find some elements.</p> <p>Table 3-1</p> <p>element</p> <p>description</p> <p>Server</p> <p>It is the SERVER element is the highest level of element of the server.xml file, and the Server element describes a Tomcat server. Generally speaking, users don't have to care about this element. A Server element is generally included in Logger and ContextManager two elements</p> <p>L o g g e r</p> <p>It is generally included that two elements of Logger and Context Manager logger are logger elements to define a log object, a log object contains the following properties: 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) verbositylevel. Represents the level of the log of this log file record. In general, the logger object is a record of Java Servlet, JSP, and Tomcat running period events CotextManager</p> <p>It is ContextManager defining a set of ContextInterceptors, RequestInterceptors, Requestinterceptors, Contexts (Context Directory for Web Applications) and their Connectors (Connectors) structure and configuration. It is ContextManager that contains some properties: Yes 1) Debug. Record the level of the log record debugging information. Is 2) home. WEBAPPS /, CONF /, LOGS / and Root Catalog Information for All Contexts. The role of this property is to start Tomcat from a directory different from Tomcat_home. 3) Workdir.Tomcat work directory.</p> <p>ContextInterceptor and Requestinterceptor</p> <p>It is the interceptor that monitors the specific event of ContextManager. ContextInterceptor monitors Tomcat's launch and end event information. RequestInterceptor listens to the request information sent by the user. General users do not need to care for these interceptors, for developers,</p> <p>Need to understand this is a method for overall operation.</p> <p>CONNECTOR</p> <p>Is the Connector object describes a connection to the user, whether it is directly from Tomcat to the user's browser or through a web server. Tomcat's working processes and read / write information and request / reply information created by different users are managed by the connector object. The configuration of the management class, TCP / IP port should be included in the configuration of the connector object.</p> <p>Context</p> <p>Each context describes a directory of a Tomcat web application. This object contains the following properties:</p> <p>Is 1) DOCBASE. This is the directory of context. Can be an absolute directory or a relative directory based on the root directory of ContextManage. Yes 2) path. This is the virtual directory location and directory name when Context is in WE B service. Yes 3) Debug. The debug information recording level of the log record.</p> <p>Is 4) Reloadable. This is to facilitate the servlet developer, when this property switch is opened, Tomcat checks if the servlet is updated and decides whether it is automatically reload it.</p> <p>Element Description Server Server Elements are the highest level of elements of the server.xml file, Server element description</p> <p>A Tomcat server, generally, users don't have to care about this element. A Server element generally includes two elements of Logger and ContextManager. The logger element defines a log object, a log object contains the following properties:</p> <p>Is 1) name. Represents the name of this log object.</p> <p>Yes 2) path. Indicates which log files are to be output to this log object.</p> <p>Is 3) verbositylevel. Represents the level of the log of this log file record.</p> <p>In general, the logger object is a record of Java Servlet, JSP, and Tomcat runtime events.</p> <p>ContextManager ContextManager defines a set of Contextinterceptors (ContextManage) (CONTEXTMANAGE)</p> <p>Event listener), requestInterceptors (event listener for ContextManage), Contexts (context directory of web applications) and their Connectors (connectors) structure and configuration. It is ContextManager that contains some properties:</p> <p>Is 1) debug. Record the level of the log record debugging information.</p> <p>Is 2) home. WEBAPPS /, CONF /, LOGS / and Root Catalog Information for All Contexts. The role of this property is to start Tomcat from a directory different from Tomcat_home.</p> <p>3) WORKDIR. Tomcat work directory.</p> <p>Both Contextinterceptor and RequestInterceptors are interceptors that monitor the specific events of ContextManager. ContextInterceptor monitors Tomcat's launch and end event information. RequestInterceptor listens to the request information sent by the user. General users do not need to care about these interceptors. For developers, it is necessary to understand that this is a global operation. The method of implementing the Connector Connector object describes a connection to the user, whether it is direct by Tomcat to the user's browser or Through a WE B server. Tomcat's working processes and read / write information and request / reply information created by different users are managed by the connector object. In the configuration of the connector object, content elements such as management classes, TCP / IP ports describe the Context Each Context describes a directory of a Tomcat's WE B application. This object contains the following properties:</p> <p>Is 1) DOCBASE. This is the directory of context. Can be an absolute directory or a relative directory based on the root directory of ContextManage.</p> <p>Yes 2) path. This is the virtual directory location and directory name when Context is in WE B service.</p> <p>Yes 3) Debug. The debug information recording level of the log record.</p> <p>Is 4) Reloadable. This is to facilitate the servlet developer, when this property switch is opened, Tomcat checks if the servlet is updated and decides whether it is automatically reload it.</p> <p>1. Add your own log file to add a logger object to join your log file, add a job is quite simple, just copy a logger object as an example, and then modify the few properties described above. After setting the logger, you can use the servletContext.log () method in your own servlet to create your own log files.</p> <p>2. Set new JSP directory</p> <p>The establishment of a new JSP work directory is relatively simple, just you need to add a Context 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.</p> <p>Problems for code protection under Windows</p> <p>When using Tomcat under Windows, there is a problem. You need to pay attention. After you can make Tomcat, type in the browser's address bar: http: // localhost: 8080 / example / jsp / helloWorld.jsp (note the suffix to capitalize ). I will find a strange phenomenon. I don't have anything in the browser window. You will find that the source code for this JSP file is fully output by Tomcat! If so, isn't any source code of the server side, it will be exposed on the Internet. In fact, the solution is very simple, write all the combinations of various suffixes to Tomcat_Home / conf / web.xml, so tomcat will treat the JSP of different retrore names, and will not disclose the code. <servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .Jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .Jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .Jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .Jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name></p> <p>JSP</p> <p></ servlet-name></p> <p><url-pattern></p> <p>* .jsp</p> <p></ url-pattern></p> <p></ servlet-maping></p> <p>Adding from Apache, IIS and Tomcat works</p> <p>Apache</p> <p>Since the Jakarta-Tomcat project is a sub-project of Apache, you can only modify the tomcat - Apache.conf file when adding a working directory to Tomcat-Apache. Perhaps the reader will feel strange, is the Tomcat-Apache.conf file is not automatically generated when Tomcat is started? It is true, but Tomcat automatically generated tomcat -apache.conf file is only a default profile provided by Tomcat. If necessary, you can modify it, then store it in another directory, or changed, and then in httpd.conf file This new file can be included in this new file. Why does Tomcat do not automatically modify the Tomcat - Apache. C O N F file to accommodate the need to add by the work directory? Tomcat did modify Tomcat-Apache.conf file, but the result of modification is obviously incorrect. For example, after server.xml added a working directory / mybook - -> C: / JSP, Tomcat repair ____ change Tomcat-Apache.conf file, add such lines: Alias ​​/ MyBook C: / Tomcat / Jakarta -tomcat / WebApps / Mybook</p> <p><Directory "C: / Tomcat / Jakarta-Tomcat / WebApps / MyBook"></p> <p>Options Indexes FollowSymlinks</p> <p></ Directory></p> <p>ApjServmount / MyBook / Servlet / MyBOOK</p> <p><Location / mybook / web-inf /></p> <p>ALLOWOVERRIDE NON</p> <p>Deny from all</p> <p></ Location></p> <p>This is obviously problematic, although the virtual directory is / MyBook, but the actual directory is not C: / Tomcat / Jakarta-Tomcat / WebApps / MyBook. View Tomcat source code c: /tomcat/jakarta-tomcat/src/org/apache/tomcat/task/apacheconfig.java file You can find that Tomcat is simply adding in front of the virtual directory when generating tomcat - apache. Conf file The default WebApp directory of the original Tomcat as a new work directory:</p> <p>PW.Println ("Alias" PATH "" </p> <p>FileUtil.Patch (Tomcathome / WebApps " PATH));</p> <p>PW.Println ("<Directory /" </p> <p>FileUtil.Patch (Tomcathome / WebApps " PATH) </p> <p>"/"> ");</p> <p>PW.Println ("Options Indexes Followsymlinks);</p> <p>PW.Println ("</ Directory>");</p> <p>So how do you solve this problem? Modifying the source code for Tomcat. However, for a general user, the Tomcat - Apache. C O N f file is more realistic. Modified methods are as follows: Alias ​​/ MyBook C: / JSP</p> <p><Directory "C: / JSP"></p> <p>Options Indexes FollowSymlinks</p> <p></ Directory> ApjServmount / MyBook / Servlet / MyBook</p> <p><Location / mybook / web-inf /></p> <p>ALLOWOVERRIDE NONE</p> <p>Deny from all</p> <p></ Location></p> <p>That is to simply simply incorrect the actual directory C: / Tomcat / Jakarta-Tomcat / WebApps / MyBook 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 Tomcat, this correct Tomcat-Apache.conf file will be regenerated by Tomcat -apache. The conf file is overwritten. Finally, restart Apache and Tomcat can be.</p> <p>2. IIS</p> <p>Almost seamless with Apache and Tomcat, IIS and Tomcat are more complicated, need to add new content to ISAPI Redirect. But okay, Tomcat's uniworkermap.conf file is simplified. Things you need to do are divided into two steps:</p> <p>1) Add a working directory to Tomcat. The previous example has been described above, which is still using / mybook- -> c: / jsp this example.</p> <p>2) Add a working directory to ISAPI Redirect. Use the text editor to open the file uniworkermap.conf, add one</p> <p>Row:</p> <p>/ mybook / * = ajp12</p> <p>Then restart IIS and Tomcat.</p> <p>Set Tomcat to start as Wi N D O W S</p> <p>Manual Start Tomcat is obviously not a suitable method using Tomcat as a WE B service, can pass under Linux</p> <p>Modify the startup script automatically starts Tomcat, and you can set Tomcat as a Windows service in Windows.</p> <p>Tomcat is a service as a Windows NT / 2000 requires tools.</p> <p>1) Download the tool, here as an example is Gservevany ---- the general application under NT as a tool running. Download the URL for http://www.advok.com/gservany.html. Unzip the z I p file and put GserveVany.exe in the WinNT / System32 directory (in order to be accidentally deleted).</p> <p>2) Enter: GserveVany -i Tomcat "C: / jakarta-tomcat" c: / jakarta-tomcat "c: / jakarta-tomcat / bin" S T A R Tomcat "C: / Jakarta-Tomcat / bin" "S TI R TO P. B A t" c: / jakarta-tomcat / bin "" shutdown.bat ".</p> <p>3) Start the service manager, you will see Tomcat Service is installed, add some comments, this service does actually do, and then modify the start-up type "Auto". Then start it. In this way, the Tomcat is successfully installed as a service under NT. 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 add Tomcat to the N t service.</p> <p>Create a new WE B application in Tomcat</p> <p>JSP is mainly technically developed to establish a We B website, which is a set of WE B files from the Web application (JSP,</p> <p>Servlet, HTML, JPG, GIFCLASS ......). Tomcat provides a range of help for the establishment of WE B applications, which are described below.</p> <p>1. Application directory and structure</p> <p>According to the Tomcat specification, from the / example example directory, Tomcat's WE B application should consist of the directory shown in Table 3 - 2. Table 3 - 2</p> <p>* .html, * .jsp, etc.</p> <p>This can have many directorys, which are determined by 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 H t m l file, the JS (JavaScript) file and CSS (style sheet) file, etc., and other multimedia files, etc.</p> <p>WEB-INF / Web.xml</p> <p>This is a description file for a WE B application. This file is an X m L file that describes S e r v L e t and this</p> <p>Other components of the WE B application include some initialization information and security constraints, etc.</p> <p>WEB-INF / CLASSES /</p> <p>This directory and its subdirectory should include all S e R v l e t files for this WE B application, and</p> <p>Compressed into other C L A S s files and related resources to the J a R packet. Note that the J A V A in this directory should follow</p> <p>Bacing organization directory</p> <p>WEB-INF / LIB /</p> <p>This catalog contains all class files and related files that are compressed into the J A R file. For example: third party</p> <p>J a v A library file, J D b C driver, etc.....</p> <p>* .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 HTML files, JSP files, there are JS (JavaScript) files and CSS (style sheets) files, and other multimedia files, etc. Web-INF / Web.xml This is a description file for a Web application. This file is an XML file that describes the other component information of the servlet and the web application, and some of the initialization information and security constraints, etc. Web-inf / classes / this directory should include this WE B. All servlet files for the application, as well as other Class files and related resources that are not compressed into the JAR package. Note that the Java class in this directory should contain all the compressed to the class files and related files compressed into the J A R file according to the package organization header Web-INF / LIB / directory. For example: the third party provided Java library file, JDBC driver, etc. ...</p> <p>2. Web.xml file</p> <p>The web.xml file contains information describing the entire web application. The following is a web.xml file as an example, explaining the individual objects inside.</p> <p>Web.xml:</p> <p><! Doctype web-app public "- // sun microsystems, inc .//dtd web coplication 2.2 // en"</p> <p>"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"></p> <p><web-app></p> <p><! -</p> <p>Main description of web applications</p> <p>-></p> <p><Display-Name> My Web Application </ display-name></p> <p><description></p> <p>Add a description of the web application here</p> <p></ description></p> <p><! -</p> <p>The following is defined below the initialization parameters of the web application.</p> <p>Use the following statement in the JSP or Servlet file</p> <p>Come get initialization parameters</p> <p>String value =</p> <p>GetServletContext (). GetInitParameter ("name");</p> <p>Here you can define any more initialization parameters</p> <p>-></p> <p><context-param></p> <p><param-name> WebMaster </ param-name> <param-value> myaddress@mycompany.com </ param-value></p> <p><description></p> <p>Here, the description of the initialization parameter is included.</p> <p></ description></p> <p></ context-param></p> <p><! -</p> <p>The following definition describes the servlet that makes up this web application, and 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. Initialization parameters can be in the servlet to:</p> <p>String value =</p> <p>GetServletConfig (). GetInitParameter ("Name");</p> <p>-></p> <p><servlet></p> <p><servlet-name> controller </ servlet-name></p> <p><description></p> <p>Join this description of this servlet</p> <p></ description></p> <p><servlet-class> com.mycompany.mypackage.controllerServlet </ servlet-class></p> <p><init-param></p> <p><param-name> Listorder </ paramname></p> <p><param-value> com.mycompany.myactions.listordersaction </ param-value></p> <p></ init-param></p> <p><init-param></p> <p><param-name> savecustomer </ paramname></p> <p><param-value> com.mycompany.myactions.savecuStomerAction </ param-value></p> <p></ init-param></p> <p><! -</p> <p>The server loaded after the server is started.</p> <p>-></p> <p><load-on-startup> 5 </ loading-on-startup></p> <p></ servlet></p> <p><servlet></p> <p><servlet-name> graph </ servlet-name></p> <p><description></p> <p>Description of this servlet</p> <p></ description></p> <p></ servlet></p> <p><! -</p> <p>Servlet mapping corresponds to a special URI request</p> <p>Relationship with a special servlet</p> <p>-></p> <p><servlet-mapping></p> <p><servlet-name> controller </ servlet-name></p> <p><url-pattern> *. do </ url-pattern></p> <p></ servlet-maping></p> <p><servlet-mapping></p> <p><servlet-name> graph </ servlet-name></p> <p><url-pattern> / graph </ url-pattern></p> <p></ servlet-maping></p> <p><! -</p> <p>Set the default session expiration time</p> <p>-></p> <p><session-config></p> <p><session-timeout> 30 </ session-timeout> <! - 30 minutes -> </ session-config></p> <p></ web-app></p> <p>3. Pack the application as a WA R file</p> <p>The WA R file is a way to pack WE B applications, using the WAR file, which is convenient to manage various related files, and reduce the volume of the entire application. Let's take a look at the syntax that will be packaged as a WAR file in WE B applications:</p> <p>Packager -Webarchive [-classpath servletorjspbean / classes [-</p> <p>ClassFiles package / myclass1.class: package / myclass2.class]]]]]]</p> <p><Content-root> [-contentfiles login.jsp: index.html: images / me.gif]</p> <p>Web.xml mywebapp.war</p> <p>Below is a simple application example, put the configuring myebpage.xml and the files in MyEbPageDir / under the package MyWebpage.war:</p> <p>Packager -Webarchive MyWebPageDir mywebpage.xml mywebpage.war</p> <p>Use the -contentfiles flag to add individual directory files</p> <p>Packager -Webarchive MyWebPageDir -ContentFiles Hello.jsp</p> <p>mywebpage.xml mywebpage.war</p> <p>Packager -webarchive mywebpagedir -contentfiles hello.jsp: Hello.html</p> <p>mywebpage.xml mywebpage.war</p> <p>Assume the servlet file in class / package / servlet1.class, specify a servlet and jsp file:</p> <p>Packager -webarchive -classpath classes mywebpagedir -contentfiles</p> <p>Hello.jsp mywebpage.xml mywebpage.war.</p> <p>The following example how to include only package / servlet1.class and packageb / servlet.class two files to the WAR file:</p> <p>Packager -webarchive -classpath classes -classfiles package /</p> <p>Servlet1.class: packageb / servlet.class mywebpagedir -contentfiles</p> <p>Hello.jsp mywebpage.xml mywebpage.war</p> <p>Finally, it is necessary to explain that every .xml file in front of each .xml file is the web.xml file mentioned earlier. The generated WAR file can be used directly in a directory containing the web application.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-10519.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="10519" 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.053</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 = 'jwHg3FyjNNp_2BcndvbayIykicuQToRpOhIm6AcuehozWpwT8ZuLxxYzd9uftayPeb6qTmnzlWRMfMgJX29w_2FGJA_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>