Web App Development Using Borland JBuilder 8 and BEA...

39
Web Application Development Using Borland ® JBuilder ® 8 and BEA WebLogic Server 7.0 Jumpstart development, deployment, and debugging servlets and JSP A Borland White Paper By Sudhansu Pati, Systems Engineer December 2002

Transcript of Web App Development Using Borland JBuilder 8 and BEA...

  • Web Application Development UsingBorland® JBuilder® 8 andBEA WebLogic Server™ 7.0

    Jumpstart development, deployment, and debugging

    servlets and JSP™

    A Borland White Paper

    By Sudhansu Pati, Systems Engineer

    December 2002

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2

    Contents

    Introduction .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Working with JSPs™ .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Create a project ..................................................................................................................... 4Attach WebLogic Server™ to the current project .................................................................. 4Attach WebLogic Server™ to all the projects........................................................................ 6Create a Web application ...................................................................................................... 6Create a JSP™........................................................................................................................ 8Make the project ................................................................................................................... 9Deploy and run JSP™ in WebLogic® Server ....................................................................... 10Remote deployment ............................................................................................................ 13Debug the JSP™ .................................................................................................................. 14

    Working with servlets .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    Optimizing Web applications .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    Optimizeit™ Code Coverage.............................................................................................. 21Optimizeit™ Profiler .......................................................................................................... 21Optimizeit™ Thread Debugger........................................................................................... 21

    Working with Apache™ Struts .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    What is Struts? .................................................................................................................... 25Create a Struts application .................................................................................................. 25Deploy and run the Struts application ................................................................................. 32

    Conclusion .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    Troubleshooting .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    Useful l inks .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Feedback and suggestions .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3

    Introduction

    Borland® JBuilder™ Enterprise is a comprehensive set of award-winning visual development

    tools for creating enterprise-scale applications written entirely in the Java™ programming

    language for the Java 2 Platform.

    This paper provides an overview of creating, testing, and debugging Web applications using

    JBuilder 8 Enterprise and BEA WebLogic Server™ 7.0 (SP1).

    The other platforms and software used to create the exercises are Optimizeit™ Suite 5,

    Microsoft® Windows XP,™ and Microsoft Internet Explorer 6.0.

    Please refer to the white paper “JBuilder 8 Configuration with J2EE Application Servers” for

    installation and configuration instructions for integrating JBuilder 8 Enterprise with

    WebLogic Server 7.0 (SP1).

    JBuilder 8 helps to develop, debug, and test Web applications written with JDK® 1.4.1, JSP™

    1.2 and Servlet 2.3 standards. It also supports older versions of JDK, JSP, and servlets.

    Followings are the list of Web technologies that can be easily developed, debugged, and

    tested using JBuilder 8 wizards. Web applications developed with other technologies not

    mentioned here may also be easily imported to JBuilder 8 and managed.

    Technology Description

    Servlets A server-side Java™ application which can process requests fromclients.

    JavaServerPages™ (JSP™)

    An extension of servlet technology. JavaServer Pages use custom taglibraries and essentially offers a simplified way to develop servlets.

    InternetBeans™Express

    A set of components and a tag library provided by Borland, used foreasier presentation and manipulation of data from a database.

    Apache™ Struts An open source tag library provided by the Jakarta Project that isused for building Web applications. Struts provides a flexible controllayer based on standard technologies like servlets, JSPs, JavaBeans,®ResourceBundles, and XML.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    4

    JavaServer PagesStandard TagLibrary (JSTL)

    A tag library provided by Sun that is part of the Java Web ServicesDevelopment Pack 1.0 (WSDP). It provides a set of tags that allowdevelopers to do common tasks in a standard way. The JSTLconsists of four areas, each with its own tag library descriptor (TLD )and namespace.

    Cocoon A servlet-based, Java publishing framework for XML that isintegrated into JBuilder.® Cocoon allows separation of content, style,and logic and uses XSL transformation to merge them. It can alsouse logic sheets and Extensible Server Pages (XSP) to deliverdynamic content embedded with program logic writtenin Java.

    Applets A specialized kind of Java application that can be downloaded by aclient browser and run on the client's machine.

    Table 1: List of major Web technologies supported by JBuilder 8

    Working with JSPs™

    Create a project

    Start JBuilder 8. Click File -> New -> Select Project tab from the Object Gallery. Click

    Project. Click OK. In the Project Wizard—Step 1 of 3 specify a Directory Name and a

    Project Name. Leave the Template as (Default Project). Hit Finish.

    For this exercise, the project directory is E:/DEMO/JBWLS and Project Name is TestWeb.

    Attach WebLogic Server™ to the current project

    You can attach the WebLogic Server to the current project. From the JBuilder main menu bar,

    click Project -> Project Properties. Click Server tab. Select WebLogic Application Server

    7.x from the combo box.

    See Figure 1 for details.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    5

    Figure 1: Project Properties window allowing users to select application server of choice

    Note: The Services panel in the left-hand side shows the services provided by the specific

    server selected in the combo box (in this case, WebLogic Server 7.0 SP1). JBuilder is

    designed to be intuitive and automatically discovers the services provided by a selected

    Web/application server. Here, all services other than Connector, Deployment, EJB,™ and

    JSP/servlet are grayed out because WebLogic Server 7.x does not provide those services.

    Note: You can click on each service from the Services panel and see what specific versions of

    different technologies are supported by the chosen Web/application server. In the above

    figure, the EJB Service is clicked from the Services panel, and JBuilder is showing the

    supported EJB versions with WebLogic Application Server 7.x.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    6

    Note: JBuilder provides users the option of choosing one server for all services in the project

    or multiple servers providing different servers. With modular services provided by different

    servers, users can configure different services to be run by different servers.

    For example, users can select Tomcat for JSP/servlet server, WebLogic Server for EJB, and

    another server for Connector.

    For simplicity, select Single server for all services in project.

    Click Deployment from the Services panel. Note that by default, the Build target for

    deploying to server is Make. If you prefer not to build the archives at the time of deployment,

    choose from the combo box. This will stop making the project during deployment

    and make the deployment faster.

    Hit OK, and JBuilder project TestWeb is now configured for WebLogic Server 7.0.

    Attach WebLogic Server™ to all the projects

    If you decide to use WebLogic Server 7.x for all of your projects, you can set this as default.

    From JBuilder menu bar click Project -> Default Project Properties. Click Server tab.

    Select WebLogic Application Server 7.x from the combo box and choose Single server for

    all services in the project.

    Create a Web application

    JBuilder allows users to create a Web application which can host applets, Web Start

    launchers, JSPs, servlets, and Apache™ Struts applications.

    From the JBuilder main menu bar, click File -> New -> Web tab in Object Gallery -> Web

    Application.

    Click OK.

    See Figure 2 for JBuilder 8 Object Gallery.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    7

    Figure 2: JBuilder 8 Object Gallery displaying the wizards to create Web applications

    The Web Application Wizard pops up. Enter Name and Directory entries for the Web

    application. For this exercise, the Web application name is TestWebApp and directory is

    TestWebApp.

    JBuilder provides an option to choose when the developers would like to build a WAR file.

    For this exercise, select When building project or webapp.

    From the JBuilder 8 project tree, expand the project and expand the Web application

    TestWebApp. Expand the deployment descriptors folder. Note that JBuilder has recognized

    that the target server is WebLogic, so it automatically created the deployment descriptors for

    WebLogic; web.xml, and weblogic.xml.

    Click web.xml. This opens the WebApp Deployment Descriptor Editor in the

    editor pane.

    See Figure 3 for details.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    8

    Figure 3: JBuilder 8 Web application Deployment Descriptor Editor

    Note: The Deployment Descriptor Editor tool in JBuilder provides a graphical user-friendly

    way to update the web.xml, and it is a two-way tool. It automatically changes the XML source

    when the Deployment Descriptor Editor is changed.

    Create a JSP™

    From the JBuilder main menu bar, click File -> New -> Web tab in Object Gallery ->

    JavaServer Page. Click OK.

    In JSP Wizard—Step 1 of 6, enter a JSP name. For this exercise, the JSP name is TestJSP.

    Note that the Web application TestWebApp is defaulted for hosting this JSP. You can check

    both the checkboxes to generate a sample bean and an error page. Click Next.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    9

    In JSP Wizard—Step 2 of 6, you can select InternetBeans™ technology, different tag

    libraries from JSTL 1.0, and Struts. Leave the defaults and click Next.

    In JSP Wizard—Step 3 of 6, enter the package name as borland.demo.web. Click Next.

    At this point, you can click Finish. JBuilder automatically creates a runtime configuration

    named TestJSP to run the created JSP.

    Note: A runtime configuration is a setup to run an application in JBuilder 8. Runtime

    configuration is essential when your project has multiple runnable files/applications and you

    want to run a specific application.

    Make the project

    To make the project, press Ctrl+Shift+F9 or click the Make icon from the JBuilder toolbar.

    JBuilder may show some warnings because of the use of some deprecated methods. To hide

    the deprecation and warning messages, click Project -> Project Properties -> Build.

    Uncheck Show warnings and Show deprecations.

    As a result of make, JBuilder automatically creates the WAR file for the Web application. The

    WAR file for this exercise is TestWebApp.war.

    See Figure 4 for details.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 0

    Figure 4: JBuilder showing the generated sources, WAR file, and Deployment Descriptors for

    WebLogic

    Deploy and run JSP™ in WebLogic® Server

    When WebLogic Server is started within JBuilder, it automatically deploys the Web

    application and runs the JSP in the JBuilder AppBrowser.™

    Figure 5 shows running of TestJSP.jsp within JBuilder.

    Enter any value in the Text Box next to Enter New Value in the AppBrowser, and the value

    is designed to be displayed next to Value of Bean Property is.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 1

    Figure 5: WebLogic Server is running within JBuilder and AppBrowser displaying the

    running JSP

    Note: JBuilder supports both hot-deployment and auto-deployment with WebLogic. Hot

    deployment is a feature that allows users to deploy/redeploy archives into Web/application

    servers and get the contents from the freshly deployed archives without restarting the

    Web/application server. With auto-deploy, users are not required to create any archives for

    deployment; they can change the files directly, and the Web/application server automatically

    activates the changes.

    By default with JBuilder, the Web application is deployed in exploded format from the project

    directory (auto-deployment). In this case, the WAR file is not used for deployment. This is the

    preferred option to work with JSP, since users do not need to redeploy to activate any

    JSP changes.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 2

    To turn off this behavior and use WARs or EARs, click Project -> Project Properties. Click

    the Server tab. Click JSP/servlet service in the Services list. On the right, de-select the

    option Map project webapps at runtime.

    If you like to see the deployment status in WebLogic console, start the WebLogic console by

    clicking Tools -> WebLogic 7.0 Admin Console.

    Expand mydomain -> Deployments -> Web Applications, and you should be able to see the

    Web application TestWebApp.

    See Figure 6 for details.

    Figure 6: WebLogic 7.0 SP1 console displaying the deployed Web application TestWebApp

    Note: If you do not see WebLogic 7.x Admin Console under JBuilder 8 Tools menu, it is

    because you have not selected this option during server configuration. Click Tools ->

    Configure Servers -> Select WebLogic Application Server 7.x from left-hand panel of

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 3

    Configure Servers window, click Custom tab from the right-hand panel, and make sure that

    checkbox against Add a Admin Console item to the Tools menu is checked.

    Remote deployment

    This section explains how to deploy an archive to a remote WebLogic Server.

    Note: The users need to have a local installation of the application server for the remote

    deployment because JBuilder needs to use the deployment utilities for that application server.

    For deploying to a remote WebLogic Server 7.x, from JBuilder menubar click Tools ->

    Enterprise Deployment. A window called WebLogic 7.x Deploy Settings pops up. Modify

    the Admin url field to point to the remote server with the remote WebLogic Server host name

    and port number (http://:).

    See Figure 7 for details.

    Figure 7: JBuilder remote deployment utility to deploy to remote WebLogic Server

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 4

    Debug the JSP™

    JBuilder supports both local and remote debugging of JSP.

    Local debuggingFor local JSP debugging, assign breakpoints in the source code wherever necessary. To assign

    a breakpoint, simply open the source file and single-click the mouse on that line.

    Note: For this exercise, the breakpoints are assigned as explained in Table 2.

    File Line#

    Breakpoints

    TestJSP.jsp 8

    TestJSPBean.java 16 Return sample;

    TestJSPBean.java 21 sample = newValue;

    Table 2: Assigning breakpoints in different files

    If WebLogic is already running, stop the WebLogic Server. Press Shift+F9 or just click the

    Debug Project icon. Click TestJSP to start WebLogic in debug mode within JBuilder. See

    Figure 8 for details.

    Note: When you click Debug Project, JBuilder starts WebLogic Server in debug mode. Now

    users can do the debug operations from JBuilder, such as seeing the thread information,

    breakpoint information, console output, step over, step into, step out, etc.

    Click the Step Over button until you see the debugger stopping at TestJSPBean.java.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 5

    Figure 8: JBuilder debugger has stopped at a breakpoint in JSP. The JSP is running

    in WebLogic

    JBuilder is designed to recognize all breakpoints and puts a red tick mark against all valid

    breakpoints and red cross mark against all non-valid breakpoints. Also, JBuilder puts a green

    arrow against the breakpoints where the debugger stops.

    Note: JBuilder debugger has an ability to debug across varieties of applications (JSP, servlets,

    JavaBeans, and Enterprise Java Beans™).

    Remote debuggingRemote debugging is useful when an application is already hosted in a staging area, and it is

    required to debug the application from a remote machine.

    Remote debugging in JBuilder is an implementation of Java Platform Debugger Architecture

    (JPDA). For more information on JPDA, visit http://java.sun.com/products/jpda/

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 6

    A JPDA transport is a form of inter-process communication used by a debugger application

    process and the virtual machine that is being debugged (often called the target VM). For more

    information on transport, visit the following link:

    http://java.sun.com/products/jpda/doc/conninv.html#Transports

    To test remote debugging for the Web application TestWebApp, you can use your machine as

    both local machine and remote server.

    Follow the steps below to remotely debug JSP.

    Open the project containing the Web application that you wish to debug. Expand the Web

    application node in the JBuilder project tree. Expand the Deployment Descriptors node (under

    the Web appnode) and double click weblogic.xml. Change weblogic.xml as shown

    in Table 3.

    Weblogic.xml

    keepgenerated

    true

    debug

    true

    precompile

    true

    http://www.bea.com/servers/wls610/dtd/weblogic-web-jar.dtd

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 7

    compileFlags

    -g

    Table 3: weblogic.xml for remote debugging of JSP using JBuilder 8 and WebLogic

    Server 7.x

    Rebuild project and deploy the Web application as a WAR file (TestWebApp.war ) to

    WebLogic Server 7.0.

    To deploy, right-click the Web application node TestWebApp from JBuilder project tree,

    click Deploy options for TestWebApp.war and click Redeploy.

    Launch WebLogic Server 7.x in the remote location with debug parameters.

    To do this, modify startWebLogic.bat in your domain directory (example

    E:\bea\user_projects\mydomain) and add the following parameters to the JAVA_OPTIONS

    variable

    -Xdebug -Xnoagent -Djava.compiler=NONE -

    Xrunjdwp:transport=dt_socket,server=y,address=5555,suspend=n

    On the local machine where you wish to debug the JSP, open the project in JBuilder. Set the

    target server to Tomcat 4.0 (or 3.3)

    On the local machine, under the source path for the project (normally PROJECT_ROOT/src),

    create a directory named jsp_servlet. If you need to use a source path other than the default,

    you can get this setting from the project properties dialog (general tab).

    On the local machine, copy the JSPs you wish to debug to this directory. In this case, copy

    TestJSP.jsp.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 8

    On the local machine, open the JSP(s) and set breakpoints where required.

    On the local machine, click Run | Configurations. Click New. Select Type as Application.

    Click the Debug tab, check the option Enable remote debugging, and select the Attach

    radio button.

    Provide a name for this configuration. Let’s assume that the configuration name is

    RemoteDebug.

    Enter the host name of the remote server in the Host name field, set the Transport type to

    dt_socket, and set the Address to the value specified in the JAVA_OPTIONS variable in

    startWebLogic.bat file. Set build target to None. Accept all other defaults.

    Click the Debug button from JBuilder main menu bar and click RemoteDebug. This should

    open a tab in JBuilder message pane. This process is called “attach to the remote server.”

    See Figure 9 for JBuilder message pane showing JBuilder attaching to remote WebLogic

    Server using socket address 5555.

    Figure 9: JBuilder 8 attaching to a remote WebLogic Server with transport socket address

    5555

    Using a browser instance, load your JSP. For this exercise, to load the JSP type the URL

    http://localhost:7001/TestWebApp/TestJSP.jsp.

    The debugger is designed to stop at breakpoints in the JSP. After the debugger stops at a

    breakpoint, the user can perform the debug operations like step out, step over, etc.

    http://localhost:7001/TestWebApp/TestJSP.jsp

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    1 9

    Working with servlets

    JBuilder provides an easy-to-use wizard to create servlets.

    Let’s create a servlet with in the same project TestWeb and Web application TestWebApp.

    From the JBuilder main menu bar, click File -> New -> Web tab of Object Gallery ->

    Servlet. Click OK.

    In Servlet Wizard–Step 1 of 5, find package name borland.web.demo from the Package

    combo box. Also enter the servlet name as TestServlet. This step allows developers to create

    a Filter servlet or a Listener servlet. Also a Single Thread Model servlet can be created, just

    by clicking the checkbox against it.

    For this exercise, lets create a Standard servlet. Click Next.

    In Servlet Wizard–Step 2 of 5, enter the methods that you want to use in the servlet. You can

    also generate an SHTML file with the servlet.

    Note: For this exercise, make sure the checkboxes against methods doget() and doPost() are

    checked and also Generate SHTML file is checked. Click Next.

    In Servlet Wizard–Step 3 of 5, you can enter the servlet name and URL pattern. Leave the

    defaults and click Next.

    In Servlet Wizard–Step 4 of 5, you can enter the Servlet Request Parameters. Click Next.

    Servlet Wizard–Step 5 of 5 allows you to create a runtime configuration for the servlet.

    Click the checkbox Create a Runtime Configuration and leave the default configuration

    name as TestServlet. At this point, the TestJSP runtime configuration is also created, so you

    can select TestJSP as the Base Configuration. Click Finish.

    Make the project. To make the project, click Ctrl +F9 or just click the Make icon from the

    JBuilder toolbar.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 0

    To deploy and run the servlet, stop WebLogic Server, if it is already running. Click the Run

    icon from JBuilder toolbar and click TestServlet. Then the AppBrowser automatically runs

    the servlet with the following URL: http://localhost:7001/TestWebApp/TestServlet.shtml

    See figure 10 for details.

    You are not required to stop WebLogic Server to deploy and run another Web application.

    If you prefer to run the servlet with your favorite browser, open your browser and type the

    following URL: http://localhost:7001/ServletTest/TestServlet.shtml.

    Figure 10: A servlet is running in WebLogic and displaying the contents in JBuilder

    AppBrowser

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 1

    Optimizing Web applications

    JBuilder 8 Enterprises provides integration with Borland Optimizeit™ Suite.

    Optimizeit Suite is a separate product. It is available for purchase and a trial download is

    available from the Borland Web site. Please visit the following link for downloading the latest

    version of Optimizeit Suite:

    http://www.borland.com/products/downloads/download_optimizeit.html

    Optimizeit Suite includes three different tools (Optimizeit™ Code Coverage, Optimizeit™

    Profiler, and Optimizeit™ Thread Debugger). For more information, visit:

    http://www.borland.com/optimizeit/index.html

    Optimizeit™ Code Coverage

    Optimizeit Code Coverage enables developers to view the execution frequency of each class,

    method, and line of code, and to reduce application footprint by removing dead code.

    Optimizeit™ Profiler

    Optimizeit Profiler enables developers to maximize application speed and reliability and to

    quickly isolate critical code that requires performance improvements.

    Optimizeit™ Thread Debugger

    Optimizeit Thread Debugger helps developers to solve mysterious thread issues easily, get the

    status of all threads and monitors in real time, avoid thread starvation and contentions that

    lead to crashes, and predict deadlocks before they occur.

    Note: During Optimizeit Suite installation, the installer automatically detects JBuilder

    installation from the user’s machine and prompts the user for integrating with JBuilder. If the

    user says OK, then both JBuilder and Optimizeit Suite are configured for tight integration.

    http://www.borland.com/optimizeit/code_coverage/index.htmlhttp://www.borland.com/optimizeit/optimizeit_profiler/index.htmlhttp://www.borland.com/optimizeit/thread_debugger/index.html

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 2

    Optimizeit Suite reads the JVMs and helps the developers with profiling, thread optimizing,

    and code covering their applications. If the JVM runs a Java application, Optimizeit Suite can

    attach to the application and display the memory, thread, and other information in a user-

    friendly way, which helps the developers to optimize their applications.

    Optimizeit Suite is a very flexible tool, and it can attach with various market leading IDEs and

    application servers.

    Visit the link http://info.borland.com/techpubs/optimizeit/ to find the supported J2EE™

    application servers, documentation, and other information about Optimizeit Suite.

    For this case, let’s attach Optimizeit Suite with WebLogic Server 7.x.

    Click the Optimize icon from JBuilder main menu bar and click TestJSP. The Runtime

    Configuration Properties window pops up and allows users to select one of the three tools

    (Profiler, Thread Debugger, and Code Coverage).

    Select Profiler from the combo box and click OK. See Figure 11 for details.

    Figure 11: Runtime configuration window to choose which Optimizeit Suite tool to use

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 3

    Click OK and WebLogic Server 7.x starts within JBuilder 8. Note that Optimizeit Profiler is

    attached to WebLogic Server 7.x and profiling the real-time JVM information. To run your

    TestJSP, right-click the JSP. Click WebRun. Click TestJSP.

    See Figure 12 for details.

    Figure 12: Optimizeit Profiler attached to WebLogic 7.x within JBuilder 8

    To go to the normal WebLogic output window, click the Console output, input and errors

    icon from the left. Also, you can click Show Virtual Machine information and Show CPU

    profiler for different operations.

    The Profiler shows information about all the classes available in the JVM. If you would rather

    see the information about your application only, type borland* in the Filters text area. This

    will show you the packages started with borland only.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 4

    To attach Optimizeit Thread Debugger with WebLogic Server 7.x, click Run ->

    Configurations -> select TestJSP -> Edit -> click Optimize -> Select Thread Debugger

    from the Type combo box.

    See Figure 13 for Optimizeit Thread Debugger starting in JBuilder and attaching WebLogic

    Server 7.x.

    Figure 13: Optimizeit Thread Debugger started in JBuilder 8 and attached with

    WebLogic Server 7.x

    Optimizeit Code Coverage can be started in the similar way. See Figure 14 for Optimizeit

    Code Coverage tool within JBuilder 8.

    Figure 14: Optimizeit Code Coverage tool started and attached to WebLogic Server 7.x

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 5

    There are lots of features available in Optimizeit Suite that helps detecting critical memory

    leaks, deadlocks, and performance issues. This paper just explained a snapshot of some of the

    features of Optimizeit Suite. Please read the Optimizeit Suite product documentation for

    information about other features of Optimizeit Suite.

    Working with Apache™ Struts

    What is Struts?

    The Struts open source framework is known as the Model 2, or Model-View Controller,

    approach to software design. This framework evolved from the Model 1 design, JavaServer

    Pages technology. This technology offered great advances from pure servlets, where

    presentation HTML was coded with lengthy out.println statements in doGet() and

    doPut() methods. JSPs offer a way to include HTML in Java code and Java code in HTML.

    However, these JSPs are difficult to read and difficult to maintain, because both Web

    designers and developers are required to work in the same set of source files.

    The Struts framework, first developed in 2001, combines the best of servlets and JSPs. The

    framework consists of a 3-tiered design paradigm: the Controller, Model, and the View. Struts

    provides its own Controller component and integrates with other technologies to provide the

    Model and the View. Using the Struts framework is now the preferred way to create robust

    and long-lived professional Web applications.

    For learning more about Struts, please visit http://jakarta.apache.org/struts/index.html. If you

    have installed JBuilder 8, you can also get information about Struts from JBuilder Help.

    Create a Struts application

    Struts is the next generation Web application development framework. But Struts applications

    can be difficult to write. A Struts application development cycle is probably two or three

    times longer than the conventional Web application development cycle.

    http://info.borland.com/techpubs/optimizeit/optimizeit5/index1280x1024.html

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 6

    But JBuilder makes the Struts application development much easier for the developers. The

    easier-to-use code wizards of JBuilder can create the Struts infrastructure efficiently and

    eliminate lot of hand coding. With the help of JBuilder, the developers now can focus on the

    business aspect of their application rather than framework development and configuration.

    While JBuilder is capable of creating very complex Struts applications, let’s create a simple

    login application (with Struts implementation) to understand the basic guidelines.

    Create a New Project in JBuilder 8 and name the project StrutsProject.

    Note :For this exercise, the location of the project is E:/DEMO/TESTWLS/StrutsProject.

    Make WebLogic Server 7.x as the target server for this project. Click Project -> Project

    Properties -> Server tab and make sure that WebLogic Application Server 7.x is selected

    from the combo box.

    Create a Web application and enter the Web application Name and Directory as LoginApp.

    Select Struts 1.0 under JSP/Servlet frameworks in the Web Application Wizard. Click

    OK.

    Expand the Web application LoginApp in the JBuilder project tree. Note that struts-

    config.xml is already created for this Struts application.

    Figure 15 shows the JBuilder Web Application Wizard, which allows the user to choose

    Struts 1.0.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 7

    Figure 15: JBuilder provides wizards to create a Struts Web application

    Note: JBuilder 8 does not officially support the beta release of Struts 1.1. However, if you

    enable your struts-config.xml file for Struts 1.1 and download the Struts 1.1 .jar file to the

    /extras folder, you will see support for Struts 1.1. The Struts Config Editor will

    display elements and attributes specific to 1.1. Additionally, if your Struts Web application

    uses a tiles.xml file for presentation, a visual editor for the Tiles configuration file is

    available.

    Create two JSPs (login.jsp and message.jsp) using the JBuilder JSP wizard. Note that JSP

    Wizard—Step 2 of 4 allows users to select Struts taglibs.

    See Figure 16 for details.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 8

    Figure 16: JSP Wizard allows users to select Struts taglibs

    For this exercise do not select any tag libraries. Edit login.jsp and message.jsp in JBuilder

    editor and copy the following code:

    login.jsp

    Login Page

    Please enter your user name and password


  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    2 9

    User Name:

    Password:

    Table 4: login.jsp: the primary JSP for this Struts application

    message.jsp

    message

    Login Successful

    Table 5: message.jsp: this JSP activates after a successful login

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 0

    Note: login.jsp is the primary JSP for this application. It accepts userName and password.

    Message.jsp displays a message to the users after successful login. login.jsp and message.jsp

    represent the View layer in this Model 2 Struts application.

    Create a Struts Action using the wizard from JBuilder Object Gallery. From Object Gallery,

    select Web tab, click Action and click OK.

    In Action Wizard—Step 1 of 2, enter the package name as borland.demo.struts and Action

    as LoginAction.

    In Action Wizard—Step 2 of 2, click the ellipses against Input JSP and select login.jsp

    from the pop-up window. Click Finish.

    The above wizard creates a file called LoginAction.java. Find the file from the JBuilder

    Project tree and edit is as shown in Table 6.

    LoginAction.javapackage borland.demo.struts;

    import org.apache.struts.action.*;

    import javax.servlet.http.*;

    import javax.servlet.RequestDispatcher;

    import java.io.IOException;

    import javax.servlet.ServletException;

    public class LoginAction extends Action {

    public ActionForward perform(ActionMapping actionMapping, ActionForm

    actionForm, HttpServletRequest httpServletRequest,

    HttpServletResponse httpServletResponse) throws IOException, ServletException {

    String userName = httpServletRequest.getParameter("userName");

    String password = httpServletRequest.getParameter("password");

    System.out.println("Username provided =" + userName);

    System.out.println("Password provided =" + password);

    if (userName!=null && password!=null &&

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 1

    userName.equals("suds") && password.equals("borland")) {

    return new ActionForward("/message.jsp");

    }

    else {

    return new ActionForward("/login.jsp");

    }

    return null;

    }

    }

    Table 6: LoginAction.java: implementation of action

    Note: The LoginAction.java file implements the action which is defined in the login.jsp. Note

    the following line from login.jsp.

    The LoginAction gets the userName and password parameters, checks the authentication and

    then commands the RequestDispacher to run either message.jsp (upon successful login) or

    login.jsp (upon unsuccessful login). For simplicity, the authentication for userName is suds

    and password is borland.

    The is available in the struts-config.xml file. Take a look at this file. It

    demonstrates how the loginAction.do in the login.jsp is mapped to the LoginAction class.

    The .do is a conventional representation of the URI. Open the web.xml and check for the

    servlet-mapping for servlet-name action. The url-pattern for action is *.do. Also action is

    nothing but an instance of the Controller Servlet org.apache.struts.action.ActionServlet.

    struts-config.xml

    http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 2

    Table 7: struts-config.xml

    Deploy and run the Struts application

    Now run the project (click F9 or click Run Project icon then login). WebLogic Server 7.x is

    designed to start within JBuilder and permit you to see the running login.jsp in the

    AppBrowser. See Figure 17 for details.

    Figure 17: JBuilder running Struts application using WebLogic Server 7.x

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 3

    Enter the user name as suds and password as borland. It is designed to show you the Login

    Successful message. Try entering some other information, and it should bring the normal

    login.jsp screen again for re-entry of user name and password.

    Conclusion

    JBuilder is a highly productive environment, and users can increase their productivity and

    reduce the project lifecycle by using JBuilder as a Java development platform. This paper is

    focused only on JSPs, servlets, and Struts applications. JBuilder has many other features

    which are designed to make the Web development a smooth experience for the developers. If

    you have JBuilder installed, try the tutorials available in JBuilder Help. Also refer to other

    white papers available on the Borland Web site for EJB and Web Services development.

    Troubleshooting

    Error 1: WebLogic Server cannot start: config.xml not

    found

    Error description

    E:\bea\user_projects\.\config.xml not found

    Since no config.xml was found, the fileRealm.properties file will not

    be used.

    Would you like the server to create a default configuration and boot?

    (y/n):

    When did this happenI tried to run WebLogic Server from JBuilder and got this error from WebLogic 7.x http:7001

    tab.

    http://bdn.borland.com/all/0,1435,s|50092|13,00.html

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 4

    CauseThe Domain Directory provided in JBuilder Server Configuration may not be correct.

    SolutionFrom the JBuilder menu bar, click Tools -> Configure Servers. Click WebLogic

    Application Server 7.x from the left-hand pane, and click Custom tab from the right. Check

    the Domain Directory. An example of Domain Directory is E:\bea\user_projects\mydomain.

    Error 2: Authentication for user denied

    Error description Configure Servers. Click WebLogic

    Application Server 7.x from the left, and click Custom tab from the right. Re-enter the

    correct user ID and password.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 5

    Error 3: Help viewer error on server in AppBrowser

    Error DescriptionHelp viewer error on server

    Unable to open location: Document not found on server.

    When did this happen:I tried to run a JSP/servlet from JBuilder, and the AppBrowser shows this error.

    CauseThe error confirms that the WebLogic Server is running properly, but the document

    JSP/servlet that you are trying to access is not found in the WebLogic server.

    Solution Redeploy the Web application and try to run the JSP/servlet again.

    Error 4: Deployment of Web application failed

    Error descriptionException:weblogic.management.ApplicationException: Prepare failed.

    Task Id = 0

    Module: TestWebApp Error: weblogic.j2ee.DeploymentException:

    Cannot deploy ServletContext(id=2545674,name=TestWebApp,context-

    path=/TestWebApp) from

    E:\bea\user_projects\mydomain\myserver\upload\TestWebApp\TestWebApp.w

    ar on myserver because there is already a webapp named

    ServletContext(id=5684736,name=TestWebApp,context-path=/TestWebApp)

    loaded from E:\Documents and

    Settings\spati\jbproject\TestWebApp\TestWebApp, which is using the

    context path /TestWebApp.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 6

    When did this happenI tried to deploy my Web archive from JBuilder to WebLogic by right-clicking the WAR

    file—> Deploy Options -> Deploy.

    CauseSeems like you have already deployed a Web application with the same name to WebLogic

    Server.

    SolutionBy default, JBuilder maps the project Web applications to WebLogic at runtime. This is

    called auto-deployment or exploded format deployment. Auto-deployment does not require

    any WAR or EAR files. WebLogic knows where to find the updated JSPs, servlets, and Java

    files.

    But if you rather use the hot deployment (deploying archives), turn off the exploded format

    deployment. Click Project -> Project Properties. Click the Server tab. Click the

    JSP/servlet service in the services list. On the right, de-select the option Map project

    webapps at runtime. Now you can deploy your WAR/EAR without any deployment

    conflicts.

    Error 5: Unable to load performance pack

    Error description

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 7

    CauseThis error occurred because the VM parameters of Configure Servers are not correct.

    WebLogic is unable to find the wlntio.dll because the path information for

    E:/bea/weblogic700/server/bin is not correct.

    SolutionClick Tools -> Configure Servers ->. Click WebLogic Application Server 7.x from the

    left-hand pane and click VM Parameters from the right-hand pane. Make sure that

    -Djava.library.path has correct path information.

    Warning 1: Deprecation warnings

    Warning description"TestJSP.jsp": Warning #: 368 : method putValue(java.lang.String,

    java.lang.Object) in interface javax.servlet.http.HttpSession has

    been deprecated at line 8

    Warning #: 369: There have been deprecation warnings. Please consult

    the documentation for a better alternative

    When did this happenWhenever I compile/build my project, I get a separate build tab in the JBuilder message pane,

    and these warning messages show there. Also, this happens when I start my WebLogic Server

    within JBuilder and deploy my archives to WebLogic.

    CauseSome of the methods created by JBuilder Wizard are deprecated.

    Solution:From JBuilder main menu bar click Project | Project Properties |Build tab and uncheck

    Show Warnings and Show deprecations.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 8

    Warning 2: Servlet failed with ServletException

    Warning description

    TestJSP from JBuilder toolbar, WebLogic Server starts within JBuilder but shows this error

    in the message.

    CauseSometimes the JSP is activated before the initialization of WebLogic Server which causes

    this error.

    Solution:This is a harmless warning message and doesn’t effect anything. If you would rather not see

    this warning message, then open the WebLogic Console ( Tools -> WebLogic 7.x Admin

    Console), expand Servers -> click myserver -> from the right-hand window, click Logging -

    > change the Stdout severity threshold from Error to Notice. Click Apply.

  • Web Application Developing Using Borland® JBuilder® 8 and BEA WebLogic Server™ 7.0

    3 9

    Useful links

    JBuilder online documentation

    http://info.borland.com/techpubs/jbuilder/jbuilder8/index1280x1024-ent.html

    Optimizeit Suite online documentation

    http://info.borland.com/techpubs/optimizeit/optimizeit5/index1280x1024.html

    Configuring Optimizeit Suite with WebLogic (to run outside of JBuilder)

    http://info.borland.com/techpubs/optimizeit/optimizeit5/integ_guide/WebLogic7.html

    Borland JDataStore™

    http://www.borland.com/jdatastore/index.html

    Link to other JBuilder white papers http://bdn.borland.com/all/0,1435,s|50092|13,00.html

    JBuilder OpenTools

    http://codecentral.borland.com/codecentral/ccweb.exe/prodcat?prodid=3&catid=11

    JBuilder WebLogic Edition download http://commerce.bea.com/downloads/jbuilder.jsp

    Feedback and suggestions

    Please send your feedback and suggestions to:

    Sudhansu Pati, Systems Engineer [[email protected]]

    100 Enterprise Way, Scotts Valley, CA 95066-3249

    www.borland.com | 831-431-1000 | Fax: 831-431-4142

    Made in Borland® Copyright © 2003 Borland Software Corporation. All rights reserved. All Borland brand and product namesare trademarks or registered trademarks of Borland Software Corporation in the United States and other countries. CorporateHeadquarters: 100 Enterprise Way, Scotts Valley, CA 95066-3249 • 831-431-1000 • www.borland.com • Offices in: Australia,Brazil, Canada, China, Czech Republic, France, Germany, Hong Kong, Hungary, India, Ireland, Italy, Japan, Korea, theNetherlands, New Zealand, Russia, Singapore, Spain, Sweden, Taiwan, the United Kingdom, and the United States. • 13728.1

    http://info.borland.com/techpubs/jbuilder/jbuilder8/index1280x1024-ent.htmlhttp://info.borland.com/techpubs/optimizeit/optimizeit5/index1280x1024.htmlhttp://info.borland.com/techpubs/optimizeit/optimizeit5/integ_guide/WebLogic7.htmlhttp://www.borland.com/jdatastore/index.htmlhttp://bdn.borland.com/all/0,1435,s|50092|13,00.htmlhttp://codecentral.borland.com/codecentral/ccweb.exe/prodcat?prodid=3&catid=11http://commerce.bea.com/downloads/jbuilder.jsp

    IntroductionTechnologyDescriptionServletsCocoon

    Working with JSPs™Create a projectAttach WebLogic Server™ to the current projectAttach WebLogic Server™ to all the projectsCreate a Web applicationCreate a JSP™Make the projectDeploy and run JSP™ in WebLogic® ServerRemote deploymentDebug the JSP™Local debuggingRemote debugging

    Working with servletsOptimizing Web applicationsOptimizeit™ Code CoverageOptimizeit™ ProfilerOptimizeit™ Thread Debugger

    Working with Apache™ StrutsWhat is Struts?Create a Struts applicationDeploy and run the Struts application

    ConclusionTroubleshootingError 1: WebLogic Server cannot start: config.xml not foundError descriptionWhen did this happenCauseSolution

    Error 2: Authentication for user deniedError descriptionWhen did this happenCauseSolution

    Error 3: Help viewer error on server in AppBrowserError DescriptionWhen did this happen:CauseSolution

    Error 4: Deployment of Web application failedError descriptionWhen did this happenCauseSolution

    Error 5: Unable to load performance packError descriptionWhen did this happenCauseSolution

    Warning 1: Deprecation warningsWarning descriptionWhen did this happenCauseSolution:

    Warning 2: Servlet failed with ServletExceptionWarning descriptionWhen did this happenCauseSolution:

    Useful linksFeedback and suggestions