facebook

Creating Web Projects

This tutorial walks you through creating and deploying a simple Hello World web project in MyEclipse. In this tutorial, you will learn how to:

  • Create a Web project
  • Create a JSP
  • Deploy and test the project
  • Debug JSP

1. Create a Web Project

  1. Select File>New>Web Project.
  2. Type HelloWorld into the Project name field. The remaining fields are filled in automatically from the MyEclipse Web project template. This template is defined in the project preferences.

    Creating a new Web project

    Following is a brief description of each field:
    Project name—The project’s name. Must be a valid Eclipse Java project name.
    Location—Clear the checkbox to specify a custom file-system location for the new project and its resources.
    Java EE version—Specifies the Java EE specification compliance level. Ensure that you select the proper specification level for the Java EE features your application requires and that your target deployment application server(s) support this specification level. Check with your application server vendor for information regarding Java EE specification level compliance.
    Add Maven support (Java EE 7 and lower)—Enabling this option includes Maven project management support in your project. See Using Maven in MyEclipse for more information. For Java EE 8 and higher versions, MyEclipse always creates Maven projects.
    Target runtime—A runtime is selected by default based on your chosen Java EE version. A runtime must be selected for various containers (Spring, JPA, Struts, etc.) to appear on your project’s build path. You can change the runtime on the Runtime tab of the Project Properties> Project Facets page.

  3. Click Finish. The wizard creates and configures the HelloWorld Web project.

    HelloWorld web project

    API JARs required for compilation and code completion support will be visible under the Maven Dependencies container, or a Java EE Library container for non Maven projects. These JARs are placed on the project’s build path but are not physically copied into your project.

2. Create a JSP

  1. Right-click the src/main/webapp  folder (or WebRoot folder for non-Maven projects) in the Explorer, and select New>JSP File.
  2. The JSP wizard is a single page form that defines the JSP’s name and location in the project. Type helloworld.jsp in the File name field.

    Creating a new JSP page
  3. Click Finish to generate the helloworld.jsp file.
  4. On line 10 in the source view, type <% out.println("Hello World"); %>.
  5. Press Ctrl+S to save the file.
    Note: The specified JSP location was the src/main/webapp folder of the  project. A location under this folder is required to  enable the JSP editor to fully provide code completion and  validation features, and for the MyEclipse Deployment Service  to deploy the JSP.

3. Deploy the Project

In this step, you deploy the HelloWorld project to the MyEclipse Tomcat server. For application server configuration details, please review the application servers tutorial document.

  1. Right-click the MyEclipse Tomcat server in the Servers view, and select Add/Remove Deployments.


    Deploying the project from the context menu
  2. Select the HelloWorld project in the Available column, and click Add.


    Deploying to the MyEclipse Tomcat Server
  3. If allowed by the server connector, you can indicate either exploded or packaged deployment by using the drop-down list beside the module in the Configured column. For this example, accept the default exploded mode.
  4. Click Finish.The context-root under which the project is deployed is /HelloWorld and is accessible at http://localhost:8080/HelloWorld. Recall that the context-root is a user-defined Web project property. To access web properties, right-click the project and select Properties>Project Facets>Web This menu option was updated in MyEclipse 2017. For prior versions, click here. .

4. Test the Application

  1. Right-click the project, and select Run As>MyEclipse Server Application.
  2. Select the MyEclipse Tomcat server, and click OK. The default index.jsp appears in your system’s default web browser. Type helloworld.jsp at the end of the URL to view your hello world message.
    Viewing the HelloWorld project in the web browser

5. Debug the JSP

  1. Double-click helloworld.jsp to open the file in the editor.
  2. Double-click the left margin of the editor on the scriplet line to add a breakpoint.
    Setting JSP breakpoint
  3. Right-click the project, and select Debug As>MyEclipse Server Application. Again, the browser opens the default index.jsp file.

  4. To debug helloworld.jsp, append the URL with helloworld.jsp, and press Enter. The MyEclipse workbench activates the Debug perspective due to the breakpoint in the file. The execution suspends at the breakpoint. The suspended line is marked with inverted color background and foreground colors. All Java variables and constructs are visible and available for modification in the Variables view. Additionally you can select a parent stack-frame in the Stack view and invoke “Drop to frame” to rollback the stack and reenter the JSP. Doing so allows you to step through execution of the JSP line by line.

    JSP breakpoint activation

    Note: If execution continues past the breakpoint without  suspending, check the breakpoint marker. If it does not include a  checkmark , then it has not been registered and activated with the Tomcat  JVM. This typically occurs when your server does not support  the JSR045 specification to enable native JSP debugging on your project. In such cases, review the server provider’s release notes,  e.g., Tomcat 4.X does not support JSP debugging natively.