Tomcat Plugin for Eclipse

Embed Size (px)

Citation preview

  • 8/6/2019 Tomcat Plugin for Eclipse

    1/33

    STEP 5: Configure Eclipse

    1. Start Eclipse by clicking eclipse.exe in the dirC:\eclipse, it will pop up a window

    (See picture 1),select directory for putting your project and then click ok.

    2. Select Window

  • 8/6/2019 Tomcat Plugin for Eclipse

    2/33

    4. Click "Add" and navigate to the JRE directory of the SDK (C:\j2sdk1.4.2_05\jre)

    .Input JRE name and click "OK".

  • 8/6/2019 Tomcat Plugin for Eclipse

    3/33

    5.Check the check box beside the JRE that you just added from the SDK you installed, as

    shown below. This sets this JRE as the default JRE to be used by Eclipse. You must do

    this for the Tomcat plugin to work. The Tomcat plugin requires that an SDK be thedefault JRE selected in these Eclipse preferences.

  • 8/6/2019 Tomcat Plugin for Eclipse

    4/33

    6. Set the Tomcat plugin preferences. First, select Tomcat from the left tree menu, then

    checkVersion 5.x, then clickBrowse to select Tomcat home (C:\jakarta-tomcat-5.0.28).

  • 8/6/2019 Tomcat Plugin for Eclipse

    5/33

    7. Select JVM Settings from the left tree menu, add tools.jar to Classpath.Then click

    OK.

  • 8/6/2019 Tomcat Plugin for Eclipse

    6/33

    STEP 6: Create and Execute a Java Applet

    1. Select File > New > Project and a NewProject window will pop up, selectJava Project, then click Next button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    7/33

    2. New Java Project window will pop up, input the name of project, here

    "AppletDemo", then clickNext button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    8/33

    3. Keep it as default and clickFinish button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    9/33

    4. Select AppletDemo (project name) in the workspace and right click on it, thenselect New > File.

  • 8/6/2019 Tomcat Plugin for Eclipse

    10/33

    5. In the pop up window New File, input the name of applet, here "SimpleApplet.java",

    then clickFinish button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    11/33

    6. Add the following code to the file SimpleApplet.java and save it.

    import java.awt.*;

    import java.applet.*;

    public class SimpleApplet extends Applet{

    public void paint(Graphics g)

    {g.setColor (new Color(0,0,255));

    g.drawString("This is a simple applet Demo", 50,50);

    }

  • 8/6/2019 Tomcat Plugin for Eclipse

    12/33

    }

    7.Select SimpleApplet.java in the workspace and right click it, then select Run>Java

    Applet.

    8. A AppletViewer window will pop up showing the running result.

  • 8/6/2019 Tomcat Plugin for Eclipse

    13/33

    9. Applet can also be viewed through a browser, to do this, you need edit a html file thatcontains the applet tag and applet class name (the applet class should be in the samedirectory, or else path should be included). Here is a example (in FrontPage editor).

  • 8/6/2019 Tomcat Plugin for Eclipse

    14/33

    10. Click the html file and the applet will show as below.

  • 8/6/2019 Tomcat Plugin for Eclipse

    15/33

    STEP 7: Create a new Tomcat Project

    1. Select File > New > Project and select a new entry Tomcat Project , thenpress Next.

  • 8/6/2019 Tomcat Plugin for Eclipse

    16/33

    2.Give project a name such as TomcatProject and press Next.

  • 8/6/2019 Tomcat Plugin for Eclipse

    17/33

    3.Keep it as default and press Finish.

  • 8/6/2019 Tomcat Plugin for Eclipse

    18/33

    4.It will pop up a window, ClickYes.

    5.A new project with a WAR structure is created in the workspace.

  • 8/6/2019 Tomcat Plugin for Eclipse

    19/33

    STEP 8: Create and execute a JSP

    1. Select TomcatProject (created in step 6) in the workspace and right click onit, then select New > File. Give the file name JSPDemo.jsp and click Finish.

  • 8/6/2019 Tomcat Plugin for Eclipse

    20/33

    2.Add the following code to the file JSPDemo.jsp and save it.

    JSP Demo

  • 8/6/2019 Tomcat Plugin for Eclipse

    21/33

    Good Morning !

    Good Afternoon!

    If you're seeing this page via a web browser, it means you've integrated Tomcat andEclipse successfully. Congratulations!

    The current time is:

    3.Start Tomcat by pressing Start Tomcat button in the toolbar.

    4.The log of startup of Tomcat will appear in the Eclipse console view.

  • 8/6/2019 Tomcat Plugin for Eclipse

    22/33

    5.Open a web browser and go to the URLhttp://localhost:8080/TomcatProject/JSPDemo.jsp . A page will load and you will get the

    following figure if followed all the above steps.

    http://localhost:8080/TomcatProject/JSPDemo.jsphttp://localhost:8080/TomcatProject/JSPDemo.jsp
  • 8/6/2019 Tomcat Plugin for Eclipse

    23/33

    STEP 9: Create and execute a Servlet

    1. Select File > New > Project. Then New Project window will pop up, selectTomcat Project then click Next button.

    2. In the New Tomcat Project window, input the project name, here use"ServletDemo",then clickNext button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    24/33

    3. To make it simple, keep this as default and clickFinish button.

  • 8/6/2019 Tomcat Plugin for Eclipse

    25/33

    4.Select WEB-INF/src in workspace and right click it and select New > File.

  • 8/6/2019 Tomcat Plugin for Eclipse

    26/33

    5.In the pop up window New File, input file name "SimpleServlet.java" and clickFinishbutton.

  • 8/6/2019 Tomcat Plugin for Eclipse

    27/33

    6. Input the following code in to the file SimpleServlet.java and clickSave button in

    toolbar.

    import java.io.PrintWriter;//import javax.servlet.*;

    public class SimpleServlet extends javax.servlet.http.HttpServlet {

    public void doGet(javax.servlet.http.HttpServletRequest request,

    javax.servlet.http.HttpServletResponse response)

  • 8/6/2019 Tomcat Plugin for Eclipse

    28/33

    throws javax.servlet.ServletException, java.io.IOException {

    performTask(request, response);

    }public void doPost(javax.servlet.http.HttpServletRequest request,

    javax.servlet.http.HttpServletResponse response)throws javax.servlet.ServletException, java.io.IOException {

    performTask(request, response);

    }

    public void performTask(javax.servlet.http.HttpServletRequest request,

    javax.servlet.http.HttpServletResponse response){

    try

    {response.setContentType("text/html");PrintWriter out = response.getWriter();

    out.println("This is a Simple Servlet Demo");

    }

    catch(Throwable theException)

    {//theException.printStackTrace();

    }

    }

    }

    7. Select WEB-INF/ in workspace and right click it and select New > File.

  • 8/6/2019 Tomcat Plugin for Eclipse

    29/33

    8. A New File window will pop up and input the file name " web.xml" and clickFinishbutton.

  • 8/6/2019 Tomcat Plugin for Eclipse

    30/33

    9. Input the following content that in the table

  • 8/6/2019 Tomcat Plugin for Eclipse

    31/33

    SimpleServlet

    SimpleServlet

    SimpleServlet

    /SimpleServlet

    into the file web.xml, for this machine it pop up a Notepad window when Finish buttonclicked in step 7. So copy the content in above table into this Notepad window, then save

    it.

  • 8/6/2019 Tomcat Plugin for Eclipse

    32/33

    10. Press the Start Tomcat button in tool bar, after tomcat starts, open a browser and

    input the URL: http://localhost:8080/ServletDemo/SimpleServlet . The result will show

    as below:

    http://localhost:8080/ServletDemo/SimpleServlethttp://localhost:8080/ServletDemo/SimpleServlet
  • 8/6/2019 Tomcat Plugin for Eclipse

    33/33

    http://plato.acadiau.ca/courses/comp/dsilver/2513/eclipseandtomcattutorial/

    http://www.eclipsetotale.com/tomcatPlugin.html

    http://plato.acadiau.ca/courses/comp/dsilver/2513/eclipseandtomcattutorial/http://www.eclipsetotale.com/tomcatPlugin.htmlhttp://plato.acadiau.ca/courses/comp/dsilver/2513/eclipseandtomcattutorial/http://www.eclipsetotale.com/tomcatPlugin.html