blob: b74d3d88d3fdd14dc1491d4b7055777e622a8be7 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../../../wtp.xsl"?>
<html>
<head>
<meta
name="root"
content="../../../../.." />
<title>test plan: Runnning a Web project on Tomcat.</title>
</head>
<body>
<h1>jst j2ee</h1>
<h2>Intoduction</h2>
<p>
This test case walkthroughs the steps required to run a web project in
the eclipse.
</p>
<BR />
<h2>Steps</h2>
<p>
<ol>
<li>
First set up Tomcat Runtime from the
Windows->Preferences->Server->Installed Runtime.
<br />
<br />
<img
border="0"
src="images/SettingTomcat_Runtime.JPG" />
<br />
<br />
<i>
Figure 1: Setup the Tomcat Runtime from
Windows->Preferences->Server->Installed Runtime.
</i>
</li>
<br />
<br />
<li>
Open J2EE perspective, from the Dynamic Web Projects, right click
and choose "New" and then choose "J2EE Web Project"
<table
cellspacing="10"
cellpadding="10">
<tr>
<td>
<img src="images/howto_open_perspective_view.jpg" />
</td>
<td>
<img src="images/perspective_view.jpg" />
</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/CreatingWebProject.JPG" />
</p>
</td>
</tr>
<tr>
<td>
<p>
<i>
Figure 3: Enter the name of the new Project,
select your Target runtime, and uncheck "Add
module to EAR project".
</i>
</p>
</td>
</tr>
</table>
</li>
<br />
<br />
<li>
Create a servlet by right clicking on the web project you
created, select "New>Class"..
<table
cellspacing="10"
cellpadding="10">
<tr>
<td>
<p>
<img src="images/CreatingServlet.JPG" />
</p>
</td>
</tr>
<tr>
<td>
<p>
<i>
Figure 4: Enter a Java package and Java name.
Select
<code>javax.servlet.http.HttpServlet</code>
as the super class.
</i>
</p>
</td>
</tr>
</table>
</li>
<br />
<br />
<li>
Open the new HeaderSnoop.java under "TestWebProject/Java
Resources/JavaSource//HeaderSnoop.java" and copy following method
into the body of the file:
<pre>
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType(&quot;text/plain&quot;);
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+&quot;:&quot;+val );
}
}
}
</pre>
</li>
<br />
<br />
<li>
Add the following declaration to your web.xml after the
display-name element:
<pre>
&lt;servlet&gt;
&lt;servlet-name>HeaderSnoop&lt;/servlet-name&gt;
&lt;servlet-class>org.test.HeaderSnoop&lt;/servlet-class&gt;
&lt;/servlet&gt; &lt;servlet-mapping&gt;
&lt;servlet-name>HeaderSnoop&lt;/servlet-name&gt;
&lt;url-pattern>/HeaderSnoop&lt;/url-pattern&gt;
&lt;/servlet&gt;
</pre>
</li>
<br />
<br />
<li>
Configure Tomcat from the Servers view in the J2EE perspective
<table
cellspacing="10"
cellpadding="10">
<tr>
<td>
<p>
<img src="images/ConfiguringServer.JPG" />
</p>
</td>
</tr>
<tr>
<td>
<p>
<i>
Figure 5: By default, the available module
groupings are presented to the user.
</i>
</p>
</td>
</tr>
</table>
</li>
<br />
<br />
<li>
Hit finish and you will see following
<table
cellspacing="10"
cellpadding="10">
<tr>
<td>
<p>
<img src="images/ServerRunning.JPG" />
</p>
</td>
</tr>
<tr>
<td>
<p>
<i>
Figure 6: By default, the available module
groupings are presented to the user.
</i>
</p>
</td>
</tr>
</table>
</li>
<br />
<br />
<li>
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.
<table
cellspacing="10"
cellpadding="10">
<tr>
<td>
<p>
<img src="images/RunningServlet.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>
<br />
<li>
Now Run the server from the Servers view, and view the servlet.
</li>
</ol>
</p>
</body>
</html>