Chapter 4. Developing a simple JSP web application

4.1. Setting Up the Project
4.2. Creating JSP Page
4.2.1. Editing a JSP Page
4.2.2. web.xml file
4.2.3. Deploying the project
4.2.4. JSP Page Preview
4.2.5. Launch JSP Project

Note:

We highly recommend developing in Seam. This chapter is for users who for some reason cannot use Seam.

In this chapter you'll find out how to create a simple JSP<diffmk:wrapper> application using the </diffmk:wrapper>JBoss Developer Studio. The application will show a classic "Hello World!" on the page.

We'll assume that you have already launched JBoss Developer Studio and also that the Web Development perspective is the current perspective. If not, make it active by selecting Window > Open Perspective > Web Development from the menu bar or by selecting Window > Open Perspective > Other... from the menu bar and then selecting Web Development from the Select Perspective dialog box.

We are going to start with the creating a Dynamic Web Project with a minimal structure, i.e. with just required facets. Thus this section will perform you all necessary steps on how to do this.


The jspHello node should appear in the upper-left Package Explorer view.


This section covers all the points how to create, edit and then preview JSP page.

<diffmk:wrapper>In our simple application we need to create only one JSP page which displays a </diffmk:wrapper>"Hello World!" message.

In the next window you can choose a template for your jsp page and see its preview.


Our hello.jsp page will now appear in Project Explorer.

<diffmk:wrapper>While creating any web project you could experience a pain writing ant scripts and managing the packaging even when writing the most trivial web applications. With </diffmk:wrapper>JBoss Developer Studio you are saved from such a pain. All you need is to start JBoss Server and launch your application in your favorite browser.

You can also create a war archive with JBDS's Archive Tools and export it to any web server.

JBDS comes with JSP design-time preview features. When designing JSP pages you can easily preview how they will look during runtime. You can even attach your stylesheet to the Preview.

  • Make a little change to hello.jsp page, e.g. put this code snippet:


<%= new java.util.Date() %>
  • Click Save button.

  • Switch to Preview page by clicking Preview tab at the bottom of the page. You will see how the page will look at runtime.

<diffmk:wrapper>Let's now launch our project on server. We'll use </diffmk:wrapper>JBoss Server that is shipped with JBoss Developer Studio. You can do it by performing one of the following actions:

  • Click the Run icon or right click your project folder and select Run As > Run on Server. If you haven't made any changes in web.xml file or cleared it out you can launch the application by right clicking the hello.jsp page and selecting Run on the Server <diffmk:wrapper>( </diffmk:wrapper><diffmk:wrapper> ).</diffmk:wrapper>

You should see the next page in a Browser :


Thus with the help of this chapter you've learnt how to organize a Dynamic Web Project with a minimal configuration, add any staff to it (in our case it's just one jsp page) and deploy and run it on the JBoss Server shipped with JBDS.