HP 5991-5565 manual Creating a Simple Application in Tomcat, # sqlplus osmsusr/osmspass@osmsdbora

Page 37

1.Log in to Oracle using the user name osmsusr and password osmspass by entering the following command:

# sqlplus osmsusr/osmspass@osmsdb_ora

2.In the Oracle database identified by the Oracle SID, osmsdb_ora, create a table named USERS, and then sequence with the osmsusr user by entering the following commands:

SQL> Create sequence hibernate_sequence start with 10 increment by 1 min value 10 maxvalue 999999999999;

SQL> Create table USERS ( user_id number(10) not null, first_name varchar(30) not null, last_name varchar2(30) not null);

SQL> Alter table USERS add ( constraint user_primary_key primary key(user_id) using index);

NOTE: The Oracle sequence, HIBERNATE_SEQUENCE, is used to generate a primary key for the table named USERS.

Creating a Simple Application in Tomcat

You must create a simple application within Tomcat to facilitate verification of this functionality. This simple application implements the insert, update, select, and delete functions for the USERS table in the MySQL or Oracle database.

Use the following steps to create a simple application in Tomcat:

1.Create a directory named $CATALINA_HOME/webapps/SimpleDemo that contains the appropriate subdirectories by entering the following commands:

#mkdir $CATALINA_HOME/webapps/SimpleDemo

#mkdir $CATALINA_HOME/webapps/SimpleDemo/META-INF

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/classes

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/lib

2.Configure the MySQL or Oracle data source by creating a file named

$CATALINA_HOME/conf/Catalina/localhost/SimpleDemo.xml. Add the following lines, depending on whether your database is MySQL or Oracle:

For a MySQL database server:

<Context>

<Resource

name="MySqlDS"

type="javax.sql.DataSource"

password="osmspass"

driverClassName="com.mysql.jdbc.Driver"

maxIdle="10"

maxWait="5000"

username="osmsusr"

url="jdbc:mysql://IP_OR_HOSTNAME_OF_DB_SERVER:3306/osmsdb" maxActive="15"/>

</Context>

For an Oracle database server:

<Context>

<Resource

name="OracleDS"

type="javax.sql.DataSource"

password="osmspass"

driverClassName="oracle.jdbc.driver.OracleDriver"

maxIdle="10"

Installing, Configuring, and Managing Web Server Middleware Stack Components 37

Image 37
Contents HP Open Source Middleware Stacks Blueprint Copyright 2007 Hewlett-Packard Development Company, L.P Table of Contents Monitor Tomcat with OpenView Tomcat SPI Oracle Database Test Webalizer Usage ReportPage List of Tables Page Introduction HP ServicesExecutive Summary Intended AudienceHP Encourages Your Comments Typographic ConventionsUserInput Feedback@fc.hp.comWeb Server Stack Architecture HP Open Source Web Server Middleware StackWeb Server Stack Architecture Installing the Linux Distribution Installing and Verifying the Linux DistributionRequired Packages and Installation Recommendations YaST Software Selection and System Tasks Verifying the Linux Distribution InstallationInstalling and Configuring Sun JDK on an HP Proliant System Configuring the Basic Apache Http ServerTomcat # /etc/init.d/apache2 startFor the alljava.sh file, add the following lines # ln -s /usr/java/jdk1.5.010 /usr/local/jdkFor the alljava.csh file, add the following lines # java -version Installing and Configuring TomcatFollowing messages appear # /usr/local/apache-tomcat/bin/startup.shUsing the Apache Http Server Benchmarking Tool Advanced Apache Http Server FeaturesIf necessary, stop Tomcat by entering the following command # /usr/local/apache-tomcat/bin/shutdown.shApache Http Server Status and Information You can correct the error by entering the followingApachemodules definition should now look like the following Restart the Apache Http Server for the changes take effectApache Server Information web page opens, as shown in Figure Apache Server Status web page opens, as shown in Figure# /etc/init.d/apache2 restart Apache Http Server Log# webalizer For detailed information, see the Webalizer website at Using Virtual Host SupportCreate the following file Configure virtual hosting by creating a file named Using Apache Http Server URL RedirectionOn the second server, create the following Html file Edit the following configuration file Using Apache Http Server Proxy FeaturesAdd the following line to the preceding file Add the following lines to the preceding fileCreate the following Html file Error Responses and RedirectsPopulate the preceding file with the following lines Using Per-User Web DirectoriesIntegrating the Web Server Stack Components Configuring the Apache and Tomcat ConnectorIf there are any errors, check the following log files Restart Apache by entering the following commandInsert the following line below the DocumentRoot line Http//YOURHOSTNAME/jsp-examplesIntegrating the Apache Web Server and Perl Integrating the Apache Web Server and PHP# rpm -q php5 apache2-modphp5 Create the following test fileIntegrating the Apache Web Server and Python Connecting Tomcat to a DatabaseWeb page displays the following text # tar zxf mysql-connector-java-version.tar.gz Connecting Tomcat and MySQL# $CATALINAHOME/bin/startup.sh # mysqladmin -u root -p create osmsdb# ps -efgrep mysqld # /etc/init.d/mysql startIf needed, start Tomcat by entering the following command Connecting Tomcat and OracleHttp//YOURHOSTNAME8080/mysqltest.jsp Test page opens as shown in FigureConfiguring the Oracle Server Obtaining and Installing the Oracle Jdbc DriverTesting the Oracle Database Connectivity Creating an Oracle Data SourceOracle Database Test Http//YOURHOSTNAME8080/oracleTest.jspInstalling Hibernate, Tomcat, and JDK Connecting Tomcat to MySQL or Oracle Using HibernateConfiguring a Database Driver in Tomcat # mysql -u root -p Password# sqlplus osmsusr/osmspass@osmsdbora Creating a Simple Application in TomcatFor a MySQL database server For an Oracle database serverAsm.jar asm-attrs.jar antlr-2.7.6rc1.jar File HibernateSessionFactory.class is generated This directory, create a Hibernate Pojo file named Preceding command creates a class file namedHttp//YOURHOSTNAME8080/SimpleDemo/hibernate.jsp Verifying the Simple Application OperationEnabling Https Support in the Apache Http Server Secure the Web Server StackRestart Apache by entering the following Apache default document root is Apache Http Server AuthorizationVerify that the certificate is displayed as in Figure Create the following test Html fileIf the login fails, the following message appears Protecting Apache Http Server Authorization with Symas CDSConfiguring Apache Http Server Services Html Head Protecting Tomcat Authorization with Symas CDSHtml Head # $CATALINA/bin/shutdown.sh # $CATALINA/bin/startup.sh Monitor Tomcat with OpenView Tomcat SPITomcat SPI Components Software Prerequisites and Reference GuidesPolicies ToolsComplete these steps Complete these steps # /sbin/SuSEfirewall2 stop Appendix B Frequently Asked QuestionsAppendix C Vendor Information Reference Appendix D Hibernate Test Application Source Code Following are the contents of the hibernate.jsp filePage Appendix D Hibernate Test Application Source Code