[Q&A] (5pt) Please write down your answers to the
following
questions on a piece of paper, and show it to the instructor before
you proceed to the Programming section.
1. Suppose your account on the CS3 server is cs320stu31, and you have a servlet Foo.java that belongs to a package bar. On the CS3 server, in which directory should you put Foo.class? Where do you put the web.xml file, and what needs to be added to web.xml so that the servlet can be accessed through the URL http://cs3.calstatelae.edu:8080/cs320stu31/FooServlet?
2. Suppose you have a JSP file Foo.jsp. Foo.jsp uses a bean of the class Bar that belongs to the package cs320.stu31. In which directories on the CS3 server should you put Foo.jsp and Bar.class? And what is the URL to access Foo.jsp?
3. A bean is said to have a write-only property foo, a read-only property bar, and a read/write property fooBar. All properties are of String type. What are the headers of the getter and/or setter methods for these properties? Note that the header of a method includes only the method name, argument(s), and return type, i.e. no method body.
4. What's the difference between the following two lines of code:
5. How do you access the value of a bean property user in a JSP using EL?
6. How do you access the value of a request parameter user in a JSP using EL? and how do you check whether the parameter value is null or an empty string?
7. What is the URL to the JSTL Tag Reference documentation?
8. Give an example of using <c:forTokens>.
[Programming] (5pt) Please upload your files to CSNS. The files should include all the source code, documentation, and an HTML file lab1.html, which contains a link to your JSP page on the CS3 server. Note that file uploading will be disabled automatically after 10:00PM, so please turn in your work on time.
For this exercise you are going to create a Calculator.jsp, which implements a simple calculator. When the JSP is requested for the first time, it displays a simple calculator like the following::
0 | |||
1 | 2 | 3 | + |
4 | 5 | 6 | - |
7 | 8 | 9 | = |
0 | Clear |
We will refer to the first row of the table above as the displaying area of the calculator, and the rest of table as the keypad, which consists of ten digit keys and four operator keys. The calculator operates like any regular calculator, where a user may input numbers and perform calculations by clicking on the keys. For example, the following table shows a sequence of clicks and the corresponding displays when a user tries to calculate 192+23-107+5.
Click | 1 | 9 | 2 | + | 2 | 3 | - | 1 | 0 | 7 | + | 5 | = | Clear | |
Display | 0 | 1 | 19 | 192 | 192 | 2 | 23 | 215 | 1 | 10 | 107 | 108 | 5 | 113 | 0 |
Calculator.jsp uses a session scope bean Calculator to perform the actual calculation. The bean consists of at least of the following methods:
Note that