Download presentation
Presentation is loading. Please wait.
1
Configuring web servers and web applications 1
2
2 Server configuration vs. application configuration A web server may run several web application Server configuration –Affects all web application running on the server –Port number –Reference to username/password database Application configuration –Affects only one web application –Welcome files –Mapping of Servlet names –Pages to handle errors –Setting session timeout –Securing the web application
3
Configuring web servers and web applications 3 Server configuration No standard –Different web servers are configured in different ways Tomcat –Configuration described in the file server.xml –TOMCAT_DIR/conf/server.xml C:\Program Files\netbeans-5.5\enterprise3\apache-tomcat- 5.5.17\conf\server.xml –Used if you run Tomcat outside NetBeans C:\Documents and Settings\anders\.netbeans\5.5\apache- tomcat-5.5.17_base\conf\server.xml –Used if you run Tomcat inside NetBeans
4
Configuring web servers and web applications 4 Web application configuration Standard –All Java enabled web servers should do it the same way Configuration described in the file WEB- INF/web.xml C:\andersb\wspj\login\web\WEB-INF\web.xml C:\Program Files\netbeans-5.5\enterprise3\apache- tomcat-5.5.17\webapps\VerySimple\WEB-INF\web.xml
5
Configuring web servers and web applications 5 The structure of web.xml The file web.xml is an XML file –Elements are tagged –The structure of the file is described in a DTD (Document Type Definition) file It’s not free format! Names on elements Sub-elements Sequence of elements Web.xml can be edited –Using any text editor Easy to make mistakes –Using NetBeans NetBeans guides you
6
Configuring web servers and web applications 6 Editing web.xml with NetBeans
7
Configuring web servers and web applications 7 Assigning names to URLs Servlets are Java classes –First letter in the Servlet name should be capital –Servlet class should be in a Java package Problem –URL will look like …/package/ServletName Package name is ugly Capital letter Solution –Assign the Servlet a virtual name in web.xml – virtualname package.ClassName –NetBeans does this when you create a new Servlet
8
Configuring web servers and web applications 8 Custom URLs Sometimes you want to make a virtual URL for a Servlet (or JSP) –Usually shorter than the original URL – virtualname /someurl –NetBeans does this when you create a new Servlet
9
Configuring web servers and web applications 9 Remapping the /servlet URL pattern Sometimes you don’t want users to call Servlets directly –Only through custom URLs –Make a special Servlet to say “sorry, no entrance” –Redirect all request for /servlet/* to this special Servlet –OH Listing 5.5 (page 290), web.xml, disabling the invoker servlet.
10
Configuring web servers and web applications 10 Initialization parameters Servlets (and JSP) may need initialization parameters –Usually read and used in the init() method –The init() method is executed ONCE. –The doGet() method is executed at each request –Initialization parameters are (name, value) pair Example –OH Listing 5.7 InitServlet.java –OH Listing 5.8 web.xml, initialization parameters
11
Configuring web servers and web applications 11 Welcome pages If a URL does not refer to a file –http://laerer.rhs.dk/andersb/http://laerer.rhs.dk/andersb/ –Which file to send in the response? Web application holds a prioritized list of welcome files –Typically: index.html, index.jsp, etc. – – index.jsp – index.html –
12
Configuring web servers and web applications 12 Pages to handle errors Two types of errors –HTTP status codes (not 2xx) Called error codes in the Java terminology –Java exceptions No caught by the Servlets Errors can be caught and special pages send as response –Like a global try block –OH Listing 5.13 + 5.14, page 307 –OH Listing 5.17 + 5.18, page 310
13
Configuring web servers and web applications 13 Session timeout When a session has been inactive for some time it should be deleted –To save memory in the server machine – – 30 – –Time unit is minutes
14
Configuring web servers and web applications 14 Deployment The file web.xml is called –“Web application deployment descriptor” Deployment –Military: Inserting material and people into a battle –Application: Moving software into a new environment Moving a web application into a new web server
15
Configuring web servers and web applications 15 Deploying a web application When you build a web application you produce a WAR file –WAR: Web Application Archive JAR: Java Application Archive –Zip file holding class files, web.xml, images, etc. But not conf/server.xml WAR files can be moved to other servers –Put in the SERVER_HOME/webapps catalog
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.