| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| "http://www.w3.org/TR/html4/loose.dtd"> |
| |
| <html> |
| |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| <title>Eclipse Web Tools Platform Project Development</title> |
| <link rel="stylesheet" href="http://www.eclipse.org/default_style.css" type="text/css"> |
| </head> |
| <body text="#000000" bgcolor="#ffffff" link="#0000ee" vlink="#551a8b" alink="#ff0000"> |
| |
| <table BORDER=0 CELLSPACING=5 CELLPADDING=2 WIDTH="100%" > |
| <tr> |
| <td ALIGN=LEFT width="60%"><font class=indextop>jst j2ee</font><br> |
| |
| <font class=indexsub>test plan: Runnning a Web project on Tomcat</font>.</td> |
| <td WIDTH="40%"> |
| <img SRC="images/Idea.jpg" HSPACE=50 height=86 width=120 align=CENTER></td> |
| </tr> |
| </table> |
| <table BORDER=0 CELLSPACING=5 CELLPADDING=2 WIDTH="100%" > |
| <tr> |
| <td ALIGN=LEFT VALIGN=TOP> <I></I></td> |
| |
| </tr> |
| <tr> |
| <td ALIGN=LEFT VALIGN=TOP BGCOLOR="#0080C0"><b> |
| <font face="Arial,Helvetica" color="#FFFFFF">Steps</font></b></td> |
| </tr> |
| |
| <tr> |
| |
| <td valign="top"> |
| <P> The following test case creates a web project and executes on Tomcat web server. </P> |
| <H2>Creating and running the Web project</H2> |
| <OL> |
| <LI><P>First set up Tomcat Runtime from the Windows->Preferences->Server->Installed Runtime.</P> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/SettingTomcat_Runtime.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 1: Setup the Tomcat Runtime from Windows->Preferences->Server->Installed Runtime.</i></p> |
| </td> |
| </tr> |
| </table> |
| |
| </LI> |
| <LI><P>Open J2EE perspective, from the Dynamic Web Projects, |
| right click and choose "New" and then choose |
| "J2EE Web Project" </P> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/howto_open_perspective_view.jpg"></p> |
| </td> |
| |
| <td> |
| <p><img src="images/perspective_view.jpg"></p> |
| </td> |
| </tr> |
| <tr> |
| <td colspan="2"> |
| <p><i>Figure 2: Open the J2EE Perspective.</i></p> |
| </td> |
| </tr> |
| </table> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/new_web_project_right_click.jpg"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 3: Right-click on the "Dynamic Web Projects" |
| group and select New>Dynamic Web Project.</i></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><img src="images/CreatingWebProject.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 4: Enter the name of the new Project, select |
| your Target runtime, and uncheck "Add module to EAR project".</i></p> |
| </td> |
| </tr> |
| </table> |
| </LI> |
| |
| <LI><P>Creating a Servlet. </P> |
| |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/new_java_class_right_click.jpg"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 5: Right-click on the web project you created, select "New>Class".</i></p> |
| </td> |
| </tr> |
| </table> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/CreatingServlet.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 6: Enter a Java package and Java name. Select |
| <code>javax.servlet.http.HttpServlet</code> as the |
| super class.</i></p> |
| </td> |
| </tr> |
| </table> |
| </LI> |
| |
| <LI><P>Open the new HeaderSnoop.java under |
| "TestWebProject/Java Resources/JavaSource/<your.package>/HeaderSnoop.java" and |
| copy following method into the body of the file:</P> |
| <PRE> |
| public void doGet(HttpServletRequest req, HttpServletResponse resp)throws |
| ServletException, IOException{ |
| resp.setContentType("text/plain"); |
| PrintWriter out = resp.getWriter(); |
| Enumeration names = req.getHeaderNames(); |
| while(names.hasMoreElements()){ |
| String name = (String)names.nextElement(); |
| String val = req.getHeader(name); |
| if( val != null ){ |
| out.println(name +":"+val ); |
| } |
| } |
| } |
| </PRE> |
| </LI> |
| <LI><P>Add the following declaration to your web.xml after the display-name element:</P> |
| |
| <PRE> |
| <servlet-name>HeaderSnoop</servlet-name><BR> |
| <servlet-class>org.test.HeaderSnoop</servlet-class><BR> |
| </servlet><BR> |
| <servlet-mapping><BR> |
| <servlet-name>HeaderSnoop</servlet-name><BR> |
| <url-pattern>/HeaderSnoop</url-pattern><BR> |
| </servlet-mapping> |
| </PRE> |
| |
| </LI> |
| <LI><P>Configure Tomcat from the Servers view in the J2EE perspective</P> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/ConfiguringServer.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 7: By default, the available module groupings are |
| presented to the user.</i></p> |
| </td> |
| </tr> |
| </table> |
| </LI> |
| <LI><P>Hit finish and you will see following </P> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/ServerRunning.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 8: By default, the available module groupings are |
| presented to the user.</i></p> |
| </td> |
| </tr> |
| </table> |
| </LI> |
| |
| <LI><P>Go to the project in the Project Explorer, select the web project, |
| right click and select "Run As", you will see Apache Tomcat, |
| create runtime configuration for the web project by selecting "New" button. |
| </P> |
| <table cellspacing="10" cellpadding="10"> |
| <tr> |
| <td> |
| <p><img src="images/RunningServlet.JPG"></p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p><i>Figure 9: By default, the available module groupings are |
| presented to the user.</i></p> |
| </td> |
| </tr> |
| </table> |
| </LI> |
| |
| <LI><P>Now Run the server from the Servers view, and view the servlet.</P></LI> |
| |
| </OL> |
| </td> |
| </tr> |
| |
| </table> |
| </body> |
| </html> |