Lab 1. Beans, EL, and JSTL
CS320, Spring 2006
[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. In which directory should you put your JSP files
- on your own computer?
- on the CS server?
2. Suppose a bean belongs to the package
cs320.stuxx. In which
directory on the CS server should you put the .class
file of
the bean so your JSP pages can use it?
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?
4. What's the difference between the following two lines of code:
- <jsp:setProperty
name="fb" property="user" value="user" />
- <jsp:setProperty
name="fb" property="user" param="user" />
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 using 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 CS server. Note that file
uploading will be disabled automatically after 7:40PM, 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::
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:
- A constructor which takes no parameter.
- public String getDisplay()
- returns a string to be displayed in the displaying area
- public void setDigit(String
digit) - set the digit clicked by a user
- public void
setOperator(String operator) - set the operator clicked by a user
Note that
- No
scripting elements are allowed in the JSP page.
- It's tricky to use special characters like +, -, or = as parameter values, so you
might want to replace them with regular characters or strings. For
example, instead of <a
href="Calculator.jsp?operator=+">, you may want to use <a
href="Calculator.jsp?operator=add"> instead.