Getting Started with WebSphere Studio Application Developer

xiaoxiao2021-03-06  223

Tim DeboerWebsphere Development Team, IBM Toronto Labo Labo October 2001

© 2001 International Business Machines Corporation. All Rights Reserved.

introduction

IBM's WebSphere® Studio Application Developer is an integrated development environment (IDE) for J2EE application developers. It provides all the tools required to create, test, and manage all elements involved in the establishment of a complete web, EJB, and EAR applications. Different and customizable concepts (ie, the view of development elements and desktop organizations) is to allow Web developers, JavaTM programmers, EJB developers, and administrators share the same development tools.

The core of Application Developer is to create a tool, editor, and wizard that quickly develops all J2EE elements (HTML files, JSPTM pages, Java classes, and servlets, EJB Beans, and XML deployment descriptors). These elements are organized in the project and correspond to the modules defined in the J2EE specification. Once an element is created, you can test and debug it in the IDE, or export and test it on the remote server.

This article will discuss the use of WebSphere Studio Application Developer beta to establish and test a simple web application. We will establish an application that converts the fancy temperature to a Celsius temperature. After establishing a small Java bean for processing temperature conversion logic, I will show how to use the JavabeanTM Web Page wizard to automatically generate the rest of the web application. The web application contains an HTML page, a JSP page, and a servlet.

See the related articles in IBM WebSphere Developer Technical Journal or online help to get information about developing EJBs using WebSphere Studiopplication Developer or the issues not covered in this article.

Create a Web Project

First we need to create a Web Project. It is a special type of project that knows how to handle web resources such as servlets, HTML, and JSP files. Web engineering provides the validation of resources and editors for Web.xml deployment description files.

Select File => New => Other Open Will List. Select Web => Web Project. Click Next. Enter myWeb in the NAME domain. Click Finish. A web project is created in the work space.

Let's take a look at the newly created MYWEB engineering directory structure. The two root folders of the project are Source and WebApplication. The WebApplication folder directly corresponds to a decompressed WAR module. In other words, the content in this folder is the real web module you created. In this folder, you can find regular files and folders existing in the web module: web-inf, web-inf / web.xml, and more.

The Source folder is used to create the Java class included in the module. Any Java source files you created in this folder will be automatically compiled into the WebApplication / Web-INF / CLASS folder.

Figure 1. Newly created web project

You will see another project in the work desk. By default, the project is named DEFAULTEAR. In the J2EE specification, the EAR module is super-container, which is to group the Web and EJB modules to deploy to a server. This EAR project is automatically generated so that this web application can be easily deployed on WebSphere Application Server in later time. Create a temperature conversion Java Bean

The core of our web application is to convert Fahrenheit to Java Bean. Please follow the steps below to create a Java Bean class.

Select myWeb project. Select File => New => Other to open the wizard list. Select Java => Java Class. Click Next. Enter com.test in the Package field. Enter TemperatureBean in the NAME domain. Click Finish. When the TemperatureBean.java editor appears, add the following code to the closed curly bracket.

// The Temperature In Celsius

Protected float temp;

Public void setTemperature (Float t) {

Temp = T;

}

Public float getTemperature () {

Return Temp;

}

Public void converttocelsius () {

TEMP = (TEMP - 32.0F) * 5.0F / 9.0F;

}

Now the code should be shown in Figure 2 below.

Figure 2. Source code of TemperatureBean.java

Save the file and turn off the editor. The next step is to use the wizard to quickly generate an HTML page in this Java Bean, a servlet and a JSP page.

Create web resources

Since Java Beans for processing temperature conversion has been created, then we need a web application UI to enter values ​​and display results. Fortunately, WebSphere Studio contains a JavaBean Web Pages Wizard that automatically generates the rest of the code. The generated code contains an HTML page, a servlet and a JSP page, which is structured to use the JavaServer PagesTM Model 2 architecture (also known as model - view - controller, named, Model-View-Controller) .

Select File => New => Other to open the wizard list. Select Web => Java Bean Web Pages. Click Next. Use the Browse button to select / MyWeb / WebApplication in the Destination Folder domain. Enter Temperature in the Web Page Prefix field. Under Java Package, click Browse. Select Com.Sample and click OK. Now the wizard page should look like the figure below. Click Next.

Figure 3. First wizard page

Under the bean domain, click Browse. Select TemperatureBean from the list and click OK. Select CONVERTTOCELSIUS () from the list. Now the wizard should appear as shown below. Click Next.

Figure 4. Second wizard page

In the table below the wizard, select the Page tab. Edit the Page Title field and enter the Temperature Conversion. Select the Temperature Domain in the list of the top left of the page. In the table below, change the Label domain to Fahrenheit. Now the wizard should look like the figure below. Click Next. Figure 5 Third wizard page

Make sure the Temperature Domain in the top left list is selected. In the table below, change the Label domain to Celsius. In the table below the wizard, select the Page tab. Edit the Page Title domain, enter Converted Temperature. Now the wizard page should look like the following. Click Finish.

Figure 6. Fourth wizard

Now the table should be shown in Figure 7 below. Note the newly generated TemperatureServletResults.java, TemperatureInputForm.html and TemperatureResults.jsp. Although TemperatureBean.java and TemperatureServletResults.java have been compiled into the WebApplication / Web-INF / CLASSES folder, they are not visible, because the browser is filtered .class file. (To turn off this feature, select Filters from the browser toolbar's drop-down menu.)

Figure 7. Workbench after the WEB resource is created

Test web application

WebSphere Studio Application Developer contains support for multiple application servers. However, one of the best features is as a newbie, you don't have to worry about any other features. To run your work, all things you have to do is just selecting a resource and requires running the resource on the server.

Select the TemperatureInputForm.html file in the MyWeb / WebApplication folder. Click Right click and select Run on Server. A new WebSphere unit test server will be created automatically. The server will be started. When it is ready, the web browser will open the correct URL of the HTML file. The web browser should be shown in Figure 8 below.

Figure 8. Temperature input page

Enter 77 in the Fahrenheit field. Click the Submit link. The JSP page is now compiled and running. This will take a few seconds. When completed, the next page will display the temperature of the converted to Celsius, as shown in Figure 9 below.

Figure 9. Convert temperature

Now, you have established and tested a web module to get an HTML file, a servlet, and a JSP page.

Can I still do something else?

Since a complete web application has been established, then you have a lot of choices. They include:

Export a WAR file - If you want to export code, you can choose to export it as a WAR file or export to a closed EAR. By file => export, both options are optional and will allow you to transfer to another workbench, deploy to WebSphere Application Server, or deploy to another J2EE server. Deploy to Remote WebSphere Application Server - When your code is working in a unit test environment, you can deploy and run on a remote copy of WebSphere Application Server. This support allows you to post to remote servers, you can remotely start and stop servers. Test on Jakarta Tomcat - Test code on Tomcat, all things you have to do are downloading a copy of the compressed Tomcat. The beta support TOMCAT version 3.2 and version 4.0 test version 5. See Online Help to get more information about these features. To get information about exporting the WAR file and deploying to a remote WebSphere Application Server, please refer to the help file: "Export Web Archive (WAR)" and "Support for Remote WebSphere Application Server". To get test information on Jakarta Tomcat, see Server Tools Help Documents. I will mention many of these aspects in the later Application Developer article.

in conclusion

We have created a web application consisting of HTML pages, servlet, and JSP pages using WEBSPHERE Studio Application Developer. You can use the JavaBean Web Pages wizard to see this web application, we can quickly create servlets, HTML files, and JSP pages that follow the JavaServer Pages Model 2 architecture.

About author

Tim Deboer is a software developer of IBM WebSphere Studio Application Developer (a Server Tools Group of IBM Toronto Lab). Together with his team members, he is currently responsible for integration throughout the Server Tools runtime and the unit test environment present in this article. He has worked with the Visualage®for Java Technical Support group to provide support for people developed using VisuaLage for Java. He is still Visualage for Java certified Solution Developer. You can contact Tim via Deboer@ca.ibm.com.

转载请注明原文地址:https://www.9cbs.com/read-128632.html

New Post(0)