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.
Go to the menu bar and select File > New > Other...
Select Web > Dynamic Web Project in the New Project dialog box
Click Next
Enter "jspHello" as a project name
Then select Minimal Configuration from the list of possible configurations and click Finish
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.
Right click <diffmk:wrapper>WebContent > New > JSP</diffmk:wrapper>.
Type "hello.jsp" for a file name and click the Next button.
In the next window you can choose a template for your jsp page and see its preview.
Select New JSP File (xhtml) template and click Finish button.
Our hello.jsp page will now appear in Project Explorer.
<diffmk:wrapper>Let's now make a little change so that a jsp page displays </diffmk:wrapper>"Hello World!" message.
<diffmk:wrapper>
Insert this line inside the
</diffmk:wrapper><diffmk:wrapper><body> </body>
</diffmk:wrapper>
<diffmk:wrapper>
tag:
</diffmk:wrapper>
<% System.out.println("Hello World!"); %>
Notice that content assist functionality is always available when you are typing:
After changes made your hello.jsp page should look like this:
This line will actually output "Hello World!" message in the Console<diffmk:wrapper>. To make the message displayed in the Browser, just replace this line with the simple </diffmk:wrapper>Hello World!.
When you are creating web project the wizard creates the web.xml for you automatically. The web.xml file editor provided by JBoss Developer Studio<diffmk:wrapper> is available in two modes: </diffmk:wrapper>Tree and Source.
Both modes are fully synchronized. Let's add mapping to our hello.jsp page in web.xml file.
Switch to Source tab.
<diffmk:wrapper>Add the next code into
</diffmk:wrapper><welcome-file-list>
<diffmk:wrapper>
:</diffmk:wrapper>
<welcome-file>hello.jsp</welcome-file>
If you come back to Tree mode you will see that the changes made are automatically reflected in that mode.
Actually you don't really need to do any configurations right now.
<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.
Project archives managing is available through Project Archives view.
Select <diffmk:wrapper>Window > Show view > Other > JBoss Tools > Project archives</diffmk:wrapper> from menu bar
Select a project in Package Explorer you want to be archived
In Project Archives you will see available archive types for the project:
Click, for example, WAR option to create war archive
In the New WAR dialog you can see automatically selected default values.
Click Next to see a stub archive configuration for your project:
Click Finish. The .war file will appear in <diffmk:wrapper>Package Explorer</diffmk:wrapper> and also in Project Archives view as structure tree:
Via Project Archives view you could now edit your archive, add new folders, publish to server, and so on:
When you are creating a web application and register it on <diffmk:wrapper>JBoss Server</diffmk:wrapper> it is automatically deployed into /deploy<diffmk:wrapper> directory of the server. JBDS comes with the feature of auto-redeploy. It means that you don't need to restart </diffmk:wrapper>JBoss Server. Any changes made in the application in exploded format will trigger a redeployment on the 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:
Start JBoss Server from <diffmk:wrapper>JBoss
Server view</diffmk:wrapper><diffmk:wrapper> by clicking the Start the server icon (
</diffmk:wrapper><diffmk:wrapper> ) .</diffmk:wrapper>
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.