Assignment # 4a
Learning Goals for Assignment 4 (all parts)
- Understand how servlets, JSPs, and beans can be combined to form a MVC Web solution.
- Understand how to use JSTL and EL in a JSP.
- Understand how to compose a JSP from various components using the JSP include directive.
This assignment is part of your project.
In Assignment#3, you developed a servlet to instantiate and populate a Java bean with the data associated with the project registration form.
In addition, the servlet invoked an isValid method of the bean to determine if the form data was valid. In Assignment#4, you will extend your
servlet to send control to one of two JSPs, depending on the return from the isValid method call.
Assignment 4a is the first of three parts in assignment 4. The three parts of assignment 4 are:
- Create a form JSP, and send a redirect (use the sendRedirect method of HttpServletResponse) to the form JSP from your controller servlet. The JSP should populate the form
with the data the user previously entered, which is stored in the bean. Your bean should have a scope that outlasts the request object.
- Build a testing JSP that displays the attributes of the shared objects, along with data submitted from the browser.
- Modify the servlet so that it forwards the request to the form JSP if the data is not valid, and forwards to a congratulations JSP if the
data was valid.
Assignment Steps (4a)
- Develop a JSP that will display the project form. The JSP should populate the fields of the form (including the selected items in the
drop down menu) using the form data previously stored in the bean (as shown in the figure above).
- The servlet should redirect to the form JSP.
- The invalid data fields should be highlighted with a red border, and an error message should appear on the page describing the error(s).
- You should continue to test for the validity of form fields (required fields contain data and e-mail address is in the correct form) as
you did in HW#3.
- Consider how you will store the handle to the bean so that the form JSP can access the bean data.
- To populate the form fields in your JSP, you will find that it is much easier to use EL, so you might want to wait until we cover EL in
class on to do this part of the assignment. In the meantime, you can populate one or two of the JSP components using a JSP Expression.
- You might want to change the asterisks in the original page to blue asterisks.
- A redirect is an http setting that tells the browser to request your JSP. You can accomplish this easily using the sendRedirect method of HttpServletResponse.
- If you want to read ahead in the text, you can use a forward instead of a redirect.
- If you are having problems in accessing the shared data, you may want to get an early start on Assignment 4b.