Likes

WCD-LAB @HOME 2-Ans 1

Create an MVC-based web application. The application will allow the user to determine the material traditionally associated with a given wedding anniversary.

Task - Design a JavaBeans Compliant Model

1. Consider the attributes needed to model the wedding anniversary problem. One writable attribute will be needed to represent the year number of the anniversary. Another, read-only, attribute will be needed to allow the view to present the name of the associated material.
2. Decide what you will call these attributes, and write them in the first column
3. Decide what the necessary corresponding methods will be to support those attributes in the JavaBeans naming conventions. Write those methods. Note that because one attribute is read-only, you will require a total of three methods, so one table cell will remain blank.
4. Decide what key name you will use to store the model in the request when it is forwarded. Write that down here:
5. Decide on the name of your model class, package name, and what, if any. base class it should extend. Write those down here:

Task
Implement the Model
1. In NetBeans. create a new web application project called SL3l4m03labl. This will also be the context root for the application.
2. Create a new class for the model and provide get and set methods as you specified.
3. In the file anniversaries.txt. you will find lists of anniversary material names with the year to which they apply. These data are provided in a form intended to simplify incorporating into a Java class. Use this form if it suits you or simply extract the raw data if you prefer to use that in creating your model. The file can be found under the Files tab (just to the right of the Projects tab in NetBeans) at the root directory of the solution for this lab.
4. (Optional) Create a trivial main method in your model to test the basic functioning of the methods.

Task • Create an HTML Form to Submit the Request
1. You will need a regular HTML form to allow the user of your application to enter the anniversary year they are interested in. When you created the project. NetBeans created an index, jsp file. Delete this file and create a new HTML page called index.html instead.
2. In the index.html file, you will create a form that prompts for a number of years. Decide what you will call the parameter when it is submitted to the web application. Write this parameter name.
3. The form will invoke an action, which will be the controller servlet that you will create shortly. Decide what the context root of this application will be. and the URL that will invoke the controller. Write these too in the Table 3-4 below.
4. Create the form in the index.html file.

Task • Create a View Component Using a JSP
1. Decide what you will call your view JSP. Write this down here:
2. Create the JSP for the view. It must present the year and anniversary material name returned by the model. Recall the name of the model as in Table 3-2 above. This will be needed along with the attribute names from Table 3-1 above to construct the EL expressions.

Task • Create the Controller
1. The final step in constructing this application is to create a controller to tie it all together. Create an HttpServlet. and ensure that it responds to the URL that you selected in Table 3-4 above.
2. Modify the processRequest method so that it:
a. Extracts the year parameter named
b. Creates an instance of the model.
c. Sets the year value in the model (consider the data type-is this a String or an int? If you convert, do not try to help the user but simply swallow any exceptions and produce a clean output. Error handling is a topic of later modules.)
d. Stores the model in the request scope using the name
e. Forwards to the view, named

Task - Run the Application

1. Right-click the project and run it.
2. Your browser should be launched automatically, and should show the input form. Enter a number of years, and press the submit button.
3. You should see appropriate output in the subsequent browser page.

1 comment:

NlabLLC said...
This comment has been removed by the author.