blob: 74441640933f89c1fffec65069d75efaa41b6cf4 [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../../../../../default_style.css" type="text/css">
<link rel="stylesheet" href="../../../../../webtools/wtp.css" type="text/css">
<title>test plan: Runnning a Web project on Tomcat.</title>
</head>
<body>
<table width="100%" cellspacing="5" cellpadding="2" border="0">
<tbody>
<tr>
<td width="60%" align="left"><font class="indextop">jst j2ee</font>
<br>
<font class="indexsub">test plan: Runnning a Web project on Tomcat.</font></td><td width="40%"><img width="120" hspace="50" height="86" align="middle" src="../../../../../images/Idea.jpg"></td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="5" cellpadding="2" border="0">
<col width="16">
<col width="*">
<tbody>
<tr>
<td valign="top" bgcolor="#0080c0" align="left" colspan="2"><b><font face="Arial,Helvetica" color="#ffffff">Intoduction</font></b></td>
</tr>
<tr>
<td valign="top" align="right">&nbsp;</td><td valign="top">
<p>
This test case walkthroughs the steps required to run a web project in
the eclipse.
</p>
</td>
</tr>
<tr>
<td valign="top" align="right">&nbsp;</td><td valign="top">
<BR>
</td>
</tr>
<tr>
<td valign="top" bgcolor="#0080c0" align="left" colspan="2"><b><font face="Arial,Helvetica" color="#ffffff">Steps</font></b></td>
</tr>
<tr>
<td valign="top" align="right">&nbsp;</td><td valign="top">
<p>
<ol>
<li>
First set up Tomcat Runtime from the
Windows-&gt;Preferences-&gt;Server-&gt;Installed Runtime.
<br>
<br>
<img border="0" src="images/SettingTomcat_Runtime.JPG">
<br>
<br>
<i>
Figure 1: Setup the Tomcat Runtime from
Windows-&gt;Preferences-&gt;Server-&gt;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&gt;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("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>
<br>
<br>
<li>
Add the following declaration to your web.xml after the
display-name element:
<pre>
&lt;servlet&gt;
&lt;servlet-name&gt;HeaderSnoop&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.test.HeaderSnoop&lt;/servlet-class&gt;
&lt;/servlet&gt; &lt;servlet-mapping&gt;
&lt;servlet-name&gt;HeaderSnoop&lt;/servlet-name&gt;
&lt;url-pattern&gt;/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>
</td>
</tr>
</tbody>
</table>
</body>
</html>