Task №1
Develop: web–application using servlets in accordance to the scenario below.
Scenario
index.htm
Controls: text field First Name, text field Last Name, radio buttons (mister, missis, miss), button Welcome.
First Name |
|
Last Name |
|
O |
mister |
O |
missis |
O |
miss |
Welcome |
Activity. User fills the form and presses the button Welcome.
Main workflow. The servlet /result is loaded.
Alternative workflow. Some of the elements is absent. The page index.htm is loaded with error description.
Servlet /result
Controls: reference Main.
Main workflow. User gets the greeting accordingly to the current time.
Task №2
Develop web–application using servlets in accordance to the scenario below.
Initial data
in.properties
numbers= val1, val2, … , valK
control= type
where val1, val2, … , valK are floating–point numbers; type is text or label.
Scenario
Servlet /data
Controls: K pairs – checkbox and value presented as text field or label accordingly to the file in.properties, references Sum, Max, Min, Avg.
√ |
val1 |
√ |
val2 |
. . . |
√ |
valK |
Sum Max Min Avg.
Activity. User fills the form and clicks some reference.
Main workflow. The servlet /result is loaded.
Alternative workflow. Field numbers in the file in.properties contains no values. User gets the message No values in the file in.properties...
Servlet /result
Controls: reference Main.
Main workflow. User gets the result of an appropriate processing in the following format:
operationName(val1, val2, …) = resultValue
or
No values in the request...
where operationName is Sum, Min, Max or Avg;
val1, val2, … – request values. If some value val is nonnumeric then it is omitted.
resultValue is the result of the operation.
User clicks Main reference and returns to the servlet /data.
Hint: learn the following example.
<HTML><HEAD>
<TITLE>test.html</TITLE>
</HEAD>
<BODY>
<form name="test" ACTION="/task2/result">
<input name="flag" type="checkbox" value="0">
<input name="val" type="input" value="135" readonly><br>
<input name="flag" type="checkbox" value="1">
<input name="val" type="input" value="71" readonly><br>
<input name="flag" type="checkbox" value="2">
<input name="val" type="input" value="-100" readonly><br>
<INPUT TYPE="SUBMIT" NAME="go" VALUE="Go">
</form>
<form name="test1" ACTION="/task2/result">
<input name="flag" type="checkbox" value="0">
<input name="val" type="input" value="135"><br>
<input name="flag" type="checkbox" value="1">
<input name="val" type="input" value="71"><br>
<input name="flag" type="checkbox" value="2">
<input name="val" type="input" value="-100"><br>
<INPUT TYPE="SUBMIT" NAME="go" VALUE="Go">
</form>
<form name="test2" ACTION="/task2/result">
<input name="flag" type="checkbox" value="135">
135<br>
<input name="flag" type="checkbox" value="71">
71<br>
<input name="flag" type="checkbox" value="-100">
-100<br>
<INPUT TYPE="SUBMIT" NAME="go" VALUE="Go">
</form>
<form name="test3" ACTION="/task2/result">
<input name="flag" type="checkbox" value="135">
<input name="val" type="input" value="135"><br>
<input name="flag" type="checkbox" value="71">
<input name="val" type="input" value="71"><br>
<input name="flag" type="checkbox" value="-100">
<input name="val" type="input" value="-100"><br>
<INPUT TYPE="SUBMIT" NAME="go" VALUE="Go"
onClick="for(i=0;i<test3.val.length;i++)test3.flag[i].value=test3.val[i].value;">
</form>
</BODY> </HTML>
//part of ="/task2/result
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String[] flags = request.getParameterValues("flag");
if(flags==null) {
out.println("No values in the request...");
} else {
for(int i=0; i<flags.length;i++) {
out.println(flags[i]);
}
}
}
}
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.