Tuesday, 1 December 2015

WCD-LAB @HOME 2-Ans 2

WCD-LAB @HOME 2-Ans 2



HTTP headers that are sent by your browser.

Preparation
No preparation is needed for this exercise.

Task • Create index, jsp and a View JSP

In this project, the MVC model will be simplified a little. The intention is that you will create a sen'let to act as controller and a JSP to act as view, but will use a String object to carry the result data directly from the sen-let to the JSP.
1. Create a new project called SL3l4m4ii.
2. Edit the automatically created index.jsp file so that it carries a single link that will lead to a relative URL. /ListHeaders. You may use an HTML anchor to do this, or if you're feeling ambitious, a submit button on an othenvise empty form.
3. Add a new JSP to the project, call this file HeadersView. jsp.
4. Add to the view introductory text such as These are the headers of your browser .
5. Add an EL expression that will output the value of a text element in the request scope called headerList.

Task • Create the Controller Servlet

1. Add a sen-let to the project. Make the fully qualified name of the sen-let sl314.m4.HeaderServlet.
2. Set the URL pattern for the sen-let to ListHeaders.
3. In the sen-let. declare a StringBuilder called result. Set the value of the result to <UL>\n .
4. Obtain the enumeration of header names from the request object.

5. For each entry in the enumeration:
a. Append <LI> to result.
b. Append the header name to result.
c. Append = to result.
d. Extract the value of the header from the request and append that value to result.
e. Append </LI>\n to the result.
6. Append </UL>\nto result.
7. Add an attribute to the request called headerList and set the value to result.
8. Forward to HeadersView.jsp.
9. Finally, run the example and verify that you see headers such as host, user-agent. accept and others.


No comments:

Post a Comment