Introduction to the Struts Web Framework 6

 

 

 

 

 

Configuring and Running the Application

 

The IDE uses an Ant build script to build and run your web application. The IDE generated the build script when you created the project, basing it on the options you entered in the New Project wizard. Before you build and run the application, you need to set the application's default entry point to login.jsp. Optionally, you can also add a simple stylesheet to the project.

 

  1. Setting the Welcome Page.

  2. Attaching a Stylesheet.

  3. Running the Application.

 

Setting the Welcome Page

 

1.      In the Projects window, double-click the web.xml deployment descriptor. The tabs listed along the top of the Source Editor provide you with an interface to the web.xml file. Click on the Pages tab. In the Welcome Files field, enter login.jsp.

 

NetBeans with struts framework project - setting the welcome/first JSP page to be served

 

NetBeans with struts framework project - the first page to be served is login.jsp page

 

NetBeans with struts framework project - login.asp page as the welcome file(s)

 

Now click on the XML tab to view the file. Note that login.jsp is now listed in the welcome-file entry:

 

<welcome-file>login.jsp</welcome-file>

 

NetBeans with struts framework project - the source code for welcome file(s)

 

Attaching a Stylesheet

 

1.      Add a simple stylesheet to the project. One easy way to do this is by saving the sample stylesheet available in the same folder as this project (for example, the web folder). The file should be visible in the NetBeans project explorer.

 

NetBeans with struts framework project - attaching the stylesheet.css file seen from physical path

 

NetBeans with struts framework project - stylesheet file seen from WEB-INF folder

 

Or, copy the file (Ctrl-C), then in the IDE, select the Web Pages node in the Projects window and press Ctrl-V). The file is added to your project.

 

2.      Link the stylesheet to your JSP pages by adding a reference between the <head> tags of both login.jsp and success.jsp:

 

<link rel="stylesheet" type="text/css" href="stylesheet.css">

 

NetBeans with struts framework project - the link to the stylesheet.css file from JSP page

 

NetBeans with struts framework project - anoter link to the stylesheet.css file from JSP page

 

Running the Application

 

1.      In the Projects window, right-click the project node and choose Run. The IDE builds the web application and deploys it, using the server you specified when creating the project. The browser opens and displays the login.jsp page.

 

 

 

 

-----------------------------------------------------------

 

NetBeans with struts framework project - running the project

 

NetBeans with struts framework project - struts project in action seen in Internet browser

 

Try entering data that should pass validation. Upon clicking Login, you are presented with the success page:

 

NetBeans with struts framework project - testing the struts project with some input data

 

NetBeans with struts framework project - the success page displayed

 

2.      Type in some data that should fail validation, i.e., either leave either field blank, or enter an email address with a missing '@' sign. When you click Login, the login form page redisplays, containing an error message:

 

NetBeans with struts framework project - testing a simple validation feature

 

NetBeans with struts framework project - input validation works properly

 

If there are any errors, they should be visible in the output windows.

 

NetBeans with struts framework project - any error(s) should be visible in the NetBeans, GlassFish web server and application output windows

 

 

 


 Strut & Web 5 | Back to Main