TOMCAT WITH ECLIPSE
JAVASERVER FACES (JSF)
GENERAL JAVA PROGRAMMING
JAVA 8 LAMBDAS & STREAMS
(WITH JQUERY UI)
INTERMEDIATE SERVLETS & JSP
ADVANCED SERVLETS & JSP
HIBERNATE & JPA
ABOUT THE INSTRUCTOR
JSF 2 & PRIMEFACES
JAVA 8 LAMBDAS & STREAMS
RESTful WEB SERVICES
HIBERNATE & JPA
SERVLETS & JSP
PUBLIC TRAINING SCHEDULE
table of contents• Executive Summary
• Verify that you can start the server.
• Check that you can access your own HTML & JSP pages.
• Set up your development environment.
• Try compiling and deploying servlets.
• More Information
Testing Server Setup
For Manual Tomcat Installation (No IDE)
After you set up Tomcat, make sure you can run it and that you can execute HTML pages, JSP pages, and servlets. Here is a quick summary; see the next sections for details.
Before trying your own servlets or JSP pages, you should make sure that the server is installed and configured properly. For Tomcat, click on install_dir/bin/startup.bat (or execute install_dir/bin/startup.sh on Unix/Linux). Next, enter the URL http://localhost/ in your browser and make sure you get the Tomcat welcome page, not an error message saying that the page could not be displayed or that the server could not be found. If you chose not to change the port number to 80 as described in the detailed configuration page, you will need to use a URL like http://localhost:8080/ that includes the port number.
If this does not work, there are a couple of things to check:
To halt the server, double click on install_dir/bin/shutdown.bat. I recommend that you make shortcuts to (not copies of) the startup and shutdown scripts and place those shortcuts on the desktop or in your main development directory. If you put them on the desktop, you can assign keyboard shortcuts, which is convenient.
After you have verified that the server is running, you should make sure that you can install and access simple HTML and JSP pages. This test, if successful, shows two important things. First, successfully accessing an HTML page shows that you understand which directories should hold HTML and JSP files, and what URLs correspond to them. Second, successfully accessing a new JSP page shows that the Java compiler (not just the Java virtual machine) is configured properly.
Eventually, you will almost certainly want to create and use your own Web applications, but for initial testing many people prefer to use the default Web application. With Tomcat and the default Web application, you put HTML and JSP pages in install_dir/webapps/ROOT or install_dir/webapps/ROOT/somePath and access them with http://localhost/filename or http://localhost/somePath/filename.
For your first tests, I suggest you simply take Hello.html and Hello.jsp and drop them into the appropriate locations. Right click on the link to download these two files to your system. If you download the files using Internet Explorer, be careful that it does not try to change the file extension, yielding Hello.htm instead of Hello.html. Note also that the preconfigured Tomcat version already contains all the test files, and has shortcuts from the development directory to the deployment locations.
If you put the files in the top-level directory of the default Web application (i.e., in install_dir/webapps/ROOT), access them with the URLs http://localhost/Hello.html and http://localhost/Hello.jsp, respectively. If you put them in a subdirectory of install_dir/webapps/ROOT, use the URLs http://localhost/directoryName/Hello.html and http://localhost/directoryName/Hello.jsp, respectively.
If you successfully started the server as
described above, but
neither the HTML file nor the JSP file works (e.g., you get File Not
Found--404--errors), you likely are using the wrong directory for the files. If the
HTML file works but the JSP file fails, you probably have incorrectly specified the
base JDK directory (i.e., with the
OK, so your environment is all set. At least you think it is. It would be nice to confirm that hypothesis. Verifying this involves the following three steps:
Details on each step are given below.
The first servlet to try is a basic one: no packages or utility (helper) classes. Rather than writing your own test servlet, you can just download HelloServlet.java into your development directory, compile it, and copy the .class file to install_dir/webapps/ROOT/WEB-INF/classes. Right-click on the link to download the file to your system. Note: in all versions of Apache Tomcat, the location for servlets in the default Web application is install_dir/webapps/ROOT/WEB-INF/classes. However, in some versions of Tomcat (including Tomcat 6.0.10), the system doesn't create the classes directory for you automatically. No problem: just create it yourself. (Remember that case matters: WEB-INF is upper case, classes is lower case.) Note that my preconfigured Apache Tomcat version already contains the classes directory and already has the sample servlets.
If you get compilation errors, go back and check your
The second servlet to try is one that uses packages but not utility classes. Again,
rather than writing your own test, you can download and install
Since this servlet is in the
Once you have placed the servlet in the proper directory, access it with the URL http://localhost/servlet/coreservlets.HelloServlet2. You should get a simple HTML page that says "Hello (2)". If the first test succeeded but this test failed, you probably either typed the URL wrong (e.g., used a slash instead of a dot after the package name) or put HelloServlet2.class in the wrong location (e.g., directly in install_dir/webapps/ROOT/WEB-INF/classes directory instead of in the coreservlets subdirectory).
The final servlet you should test to verify the configuration of
your server and development
environment is one that uses both packages and utility classes.
is a servlet in the
If you get compilation errors such as "
Please don't send me email about unresolved symbol errors until you have confirmed that HelloServlet3.java and ServletUtilities.java are in a subdirectory called coreservlets, and that the directory above this is in the CLASSPATH.
Once you compile HelloServlet3.java (which will automatically cause ServletUtilities.java to be compiled), copy (don't move!) the entire coreservlets subdirectory from your development location to install_dir/webapps/ROOT/WEB-INF/classes. Then, access the servlet with the URL http://localhost/servlet/coreservlets.HelloServlet3 (again, note that it is a dot, not a slash, between the package name and the servlet name). You should get a simple HTML page that says "Hello (3)".
|© 2015 coreservlets.com | Design by TBIQ | Java hosting from Kattare|