Deploying the Web Application

Normally, when deploying a Web application that uses servlets, it's common practice to put all the necessary Java classes into a .jar file, put them in a specific directory, and modify a configuration file so that the Web container recognizes it.

This is not necessary for OC4J at least for development purposes. It is necessary only to put the Java source files in the default servlet directory and the JSP, HTML and any other resource files (.gif or .jpg, if we have any) go in the default-web-app directory. OC4J will automatically compile not only the JSPs but also the Java source files.

To deploy the application we've built so far:

  • Copy MusicServlet.java, HttpController.java, ResultsPage.controller.java, MusicResults.java, CDInfoController.java, and MessengerBean.java to

     default-web-app\WEB-INF\classes 
  • Copy StartPage.jsp, MusicSearch.jsp, and NotImplemented.jsp to

     default-web-app 
  • Copy the PageClasses.properties file to

     config 
  • In the config directory, open the global-web-application.xml file with a text editor and change the value of the development attribute orion-web-app tag to true. It should appear as follows:

     <orion-web-app jsp-cache-directory="./persistence" servlet-webdir="/servlet" development="true" > 

Changing the development attribute in the global-web-application.xml file will cause OC4J automatically to recompile servlets when they are updated. But beware that OC4J does not notice changes to classes that are not servlets. To get the helper classes to recompile, it may be necessary to delete the .class files, then stop and restart the server.

Assuming that all the files are in the right place and OC4J is running (and that the Oracle database is running too, of course), we can try running the MusicServlet application.

Running the MusicServlet Web Application

After deploying the application as described above, entering the following address in your browser should start the application:

 http://localhost:8888/servlet/MusicServlet 

The servlet directory is necessary because this was specified as the default servlet in the orion-web-app tag in the global-web-application.xml file that we saw above. MusicServlet, of course, is the name of the servlet we want to run.

The first time we run the MusicServlet application, it will take a while to load, because the container needs to compile the servlet and JSP files. It will be much faster thereafter.

One thing that should be pointed out is that standard output from the servlets and Java classes are sent to the console. This allows us to use System.out.println() for debugging, in lieu of a more interactive development environment, such as JDeveloper.

Stopping the OC4J Server

To stop the OC4J server, open another command prompt window and enter the following command in the OC4J home directory:

 java -jar admin.jar ormi://localhost admin adminpwd -shutdown 


Java Oracle Database Development
Java Oracle Database Development
ISBN: 0130462187
EAN: 2147483647
Year: 2002
Pages: 71

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net