1 / 33

Configuring Linux and Servlets

Configuring Linux and Servlets. John Ternent John@ternent.com. (c) 1999, Arthur Andersen, LLP. Overview. Server-based processes Servlet architecture overview Servlet engines Installation, Configuration, and Usage Apache JServ Live Software (Allaire) JRun JDBC Servlet

harken
Download Presentation

Configuring Linux and Servlets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Configuring Linux and Servlets John Ternent John@ternent.com (c) 1999, Arthur Andersen, LLP (c) 1999, Arthur Andersen, LLP

  2. Overview • Server-based processes • Servlet architecture overview • Servlet engines • Installation, Configuration, and Usage • Apache JServ • Live Software (Allaire) JRun • JDBC Servlet • Futures - Tomcat, J2EE, JSP • Q&A (c) 1999, Arthur Andersen, LLP

  3. Server-Side Processes • Brief overview of HTTP • CGI processes • Innovations – ISAPI, NSAPI, Servlets, FastCGI Web Server Files ? ? External Services Business Logic ? Databases (c) 1999, Arthur Andersen, LLP

  4. Server-Side Solutions • ISAPI/NSAPI – Proprietary delegation mechanisms for running logic in-process. • Servlets – Generic, Java-based mechanism for creating business logic. Write Once, Run Anywhere? YES! Apache Netscape IIS Connector Connector Connector Servlet Runner JSDK Servlet Servlet Servlet Servlet (c) 1999, Arthur Andersen, LLP

  5. Servlet Architecture • Common request/response HTTP model • HttpServletRequest • HttpServletResponse • Servlet lifecycle • init() • service() • doGet()/doPost() • destroy() • Security sandbox • Exception handling (c) 1999, Arthur Andersen, LLP

  6. Our First Servlet! import java.io.PrintWriter;import javax.servlet.*; import javax.servlet.http.*; public class MyServlet extends HttpServlet { public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException { //need to catch ioExceptions here res.setContentType(“text/html”); PrintWriter out = res.getWriter(); out.println(“<HTML><BODY>”); out.println(“<H1>Linux Rocks!</H1>”); out.println(“<H3>Thanks for visiting from” + req.getRemoteAddr() + “!</H3>”); out.println(“</BODY></HTML>”); out.close(); }}

  7. Our First Servlet!

  8. Servlet Engines • Plug-Ins • Apache JServ (www.apache.org) • Live Software (Allaire) JRun (www.allaire.com) • New Atlanta ServletExec (www.newatlanta.com) • IBM ServletRunner (software.ibm.com/webservers) • WAICoolRunner (NS only – www.gefionsoftware.com) • Others (c) 1999, Arthur Andersen, LLP

  9. Servlet Engines • Servlet-enabled Servers • O’Reilly WebSite (website.oreilly.com) • BEA Weblogic (weblogic.beasys.com) • W3C Jigsaw (www.w3.org/jigsaw) • GemStone/J (www.gemstone.com) • Includes New Atlanta ServletExec (c) 1999, Arthur Andersen, LLP

  10. Step 1 – Get Thee a Web Server! • For most Linux users – Apache is the way to go. • For some distributions, it may be wise to download and recompile. • Make sure you get at least version 1.3.6 and enable DSO support! • compile with : --enable-rule=SHARED_CORE --enable-module=so • I like mine in /usr/local/apache. (c) 1999, Arthur Andersen, LLP

  11. Step 2 – Get Thee an Engine! • For Linux – either JServ or JRun is probably best choice. • JRun is commercial, but has 5-connection unlimited evaluation • JServ is free (it’s from Apache) (c) 1999, Arthur Andersen, LLP

  12. Step 3a.1 – Install JServ • gunzip/tar the downloaded file  /usr/local • cd /usr/local/Apache-JServ1.0 • Install a Java Virtual Machine (1.1 or better) • Tip: I’ve got various VMs from Blackdown (www.blackdown.org) and IBM (www.alphaworks.ibm.com/tech/linuxjvm) installed in /usr/local/dev and use the symbolic link /usr/local/dev/jdk to point to different directories as I need them. • Ensure an ANSI C compiler is available. (c) 1999, Arthur Andersen, LLP

  13. Step 3a.2 – Install JServ • Install the Sun Java Software Development Kit (java.sun.com/products/servlet/index.html) • Warning – You must install version 2.0 of the JSDK, not any earlier, not any later, and not the JWSDK (confused enough?). • I install this to /usr/local/dev/JSDK2.0. • No configuration required • Verify apache installation (http://localhost/). • Verify JDK installation (>java –version) • Verify Apache DSO support (>/usr/local/apache/bin/ httpd –l must show mod_so.c) (c) 1999, Arthur Andersen, LLP

  14. Step 3a.3 – Install JServ • cd /usr/local/Apache-JServ1.0 • ./configure \ --prefix=/usr/local/jserv \ --with-apache-install=/usr/local/apache \ --with-jdk-home=/usr/local/dev/jdk \ --with-jsdk=/usr/local/dev/JSDK2.0 \ --disable-debugging • make install • don’t just do “make”, as in instructions, or mod_jserv.so won’t get moved to libexec (c) 1999, Arthur Andersen, LLP

  15. Step 4a.1 – Configure JServ • Servlet Zones • analogous to virtual web hosts • example zone created by default • controlled by zone.properties file • specify repositories (directories), which map to zones • Add to httpd.conf: • Include /usr/local/ApacheJServ-1.0/example/jserv.conf (c) 1999, Arthur Andersen, LLP

  16. Step 4a.2 – Configure JServ • Configuration files: • jserv.conf : Apache/JServ integration • example/jserv.properties : General parameters and zones • conf/zone.properties : zone repositories and security (c) 1999, Arthur Andersen, LLP

  17. Step 4a.3 – Configure JServ • Create a new zone: • jserv.properties: • Servlet Zone parameters • zones=example,testJServ • Configuration file for zones • testJServ.properties=/usr/local/servlet/JServ/testJServ.properties • cp $JServ/conf/zone.properties to […]/JServ/testJServ.properties • testJServ.properties: • repositories=/usr/local/servlet/JServ • Mount new servlet zone • jserv.conf: • ApJSevMount /testJServ /testJServ • Restart apache • Test servlet: http://localhost/testJServ/MyServlet (c) 1999, Arthur Andersen, LLP

  18. Step 5a – Verify JServ Installation • Restart Apache • /usr/local/apache/bin/apachectl restart • Logs will tell you if JServ is running • cat /usr/local/apache/logs/error_log • [Date] [notice] Apache/1.3.6 (Unix) ApacheJServe/1.0 configured – resuming normal operations • http://localhost/example/Hello (c) 1999, Arthur Andersen, LLP

  19. Step 3b.1 – Install JRun • Download and tar –xzvf JRun • I put it in /usr/local/jrun • No additional software (JSDK) required – JRun includes its own servlet.jar file • From an X terminal session: • /usr/local/jrun/install.sh • Starts graphical install wizard (hooray!) (c) 1999, Arthur Andersen, LLP

  20. Step 3b.2 – Install JRun • Specify JRun root directory • /usr/local/jrun • Select Older JRun root directory [optional] • <JRun sets up property files> • Enter license key [optional] • Enable CF_Anywhere [optional] • Select JSP mapping {0.92 or 1.0} • Select Web Server • Apache 1.2/1.3 (c) 1999, Arthur Andersen, LLP

  21. Step 3b.3 – Install JRun • Select Proxy Host and Proxy Port • 127.0.0.1 & 8081 is fine, usually • Specify JRun Service Manager • Leave as “default” • Specify Apache conf directory • /usr/local/apache/conf • DSO Support options <CAREFUL!> • Use 1.3.6 DSO • Finish (hooray again!) (c) 1999, Arthur Andersen, LLP

  22. Step 4b.1 – Configure JRun • JRun has its own visual administration tool • /usr/local/jrun/jsm-default/startadmin.sh • All commands are accessible from property files • Select Configure for jsm-default • Most relevant configuration is either under jse service or under General tab of main admin console. (c) 1999, Arthur Andersen, LLP

  23. Step 4b.2 – Configure JRun • General tab: • General JRun Service Manager Settings • Java Environment settings • Java Executable • Java Arguments (JIT, for example) • Java Classpath (can put servlet directories in here) • Library Path (natives) • Java Security Manager (c) 1999, Arthur Andersen, LLP

  24. Step 4b.3 – Configure JRun • jse Service Config options: • General • includes servlet directories (somewhat flaky) • Mapping • maps extensions and paths, like /servlet or *.jsp • Aliases • Translate packaged name to simple name • MIME Filters • links MIME types to servlets • Multi-Home • Maps URL hosts to different servlet directories • Session Tracking (c) 1999, Arthur Andersen, LLP

  25. Step 5b – Verify JRun Installation • Restart Apache • /usr/local/apache/bin/apachectl restart • Logs will tell you if JRun is running • cat /usr/local/apache/logs/error_log • [Date] [notice] jrApache[init] mod_jrun: JRun Connector v2.3.148 Apache – [Release Date] • Start JRun • /usr/local/jrun/jsm-default/startjsm.sh • http://localhost/servlet/SnoopServlet • Stop JRun • /usr/local/jrun/jsm-default/stopjsm.sh (c) 1999, Arthur Andersen, LLP

  26. Tips and Tricks • Know the caching policies for the servlet engine and the web server. • Watch your classpaths! • Odd things can get included unintentionally • Include servlet api – jsdk or engine-specific • Watch String concatenation problems – use StringBuffers or print to the Writer directly. • Use an HTML generation class to enforce good HTML practices. • During development, use –Djava.compiler=NONE to prevent JIT from executing. • Advanced Configuration Options: Instances, Threads, Load Balancing (c) 1999, Arthur Andersen, LLP

  27. Servlet Examples • Connect to JDBC Database • Connect to CORBA Service (c) 1999, Arthur Andersen, LLP

  28. Example 1 – JDBC import java.io.*; import java.sql.*; import javax.servlet.http.*; import javax.servlet.*; public class TestFlush extends HttpServlet { public void init (ServletConfig conf) throws ServletException { super.init(conf); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (ClassNotFoundException cnf) { throw new ServletException ("Class not found"); } }

  29. Example 1 - JDBC public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException { try { PrintWriter out = res.getWriter(); res.setContentType("text/html"); out.println("<HTML><HEAD><H3>Test JDBC</H3></HEAD><BODY>"); out.println("<TABLE BORDER=1 WIDTH=75%>"); Connection conn = DriverManager.getConnection("jdbc:odbc:myDSN","",""); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM Table1;"); ResultSetMetaData rsm = rs.getMetaData(); out.println("<TR>"); for (int i = 1; i <= rsm.getColumnCount(); i++) { out.println("<TH>“ + rsm.getColumnName(i) + “</TH>"); } out.println("</TR>");

  30. Example 1 - JDBC while (rs.next()) { out.println("<TR>"); for (int i = 1; i <= rsm.getColumnCount();i++) { out.println("<TD>“ + rs.getString(i) + "</TD>“); } out.println("</TR>"); } out.println("</BODY></HTML>"); } catch (SQLException se) { throw new IOException("SQL Exception"); } } }

  31. Example 1 - JDBC

  32. Futures • JSPs • Tomcat • J2EE • WebLogic (c) 1999, Arthur Andersen, LLP

  33. Resources • Jason Hunter’s Java Servlet Programming (O’Reilly) and www.servlets.com • www.servletcentral.com • www.javaworld.com • java.sun.com/products/servlet/index.html (c) 1999, Arthur Andersen, LLP

More Related