Title: ServletJSP and HtmlFixture exercises
1Servlet-JSP and HtmlFixture exercises
2- Exercises
- http//sra.itc.it/people/marchetto/courses/trento
/lsa/07/ - 1- Hello World
- a) write a JSP application
- b) write a test case
- 2- NameWeb, three tasks
- a) bug fixing
- b) maintenance
- c) evolution
3Preliminary Steps - Download fitnesse.zip
http//sra.itc.it/people/marchetto/courses/trento/
lsa/07/code/fitnesse.zip - Unzip it into the
desktop - Take a note of the directory path
4Exercise 1
- Hello World
- Write a JSP page that writes the string Hello
World - Write a Fit-Table that uses the HtmlFixture to
test the - JSP page
5A) Write the JSP (a)
- Download the zip file exercise1.zip and put
it in the desktop http//sra.itc.it/people/marche
tto/courses/trento/lsa/07/code/exercise1.zip -
Import it into Eclipse File?Import?Existing
Project into Workshopace and click next
? select Archive File ? Browser your desktop
to select the exercise1.zip ? click
Finish - In the new Eclipse project --
(if needed) create a directory called "work" if
it doesn't exist -- (if needed) delete
subdirectories of the directory "work" if it
exist and contains errors
6A) Write the JSP (b)
- - (if needed) Start Tomcat or restart it
- open the "Tomcat project" menu
(right-button mouse in the - project) and update the Tomcat context
- - Open a browser and call the page Hello.jsp
- (e.g., http//localhost8080/ex1/Hello.jsp)
7A) Write the JSP (c)
- - Complete the Hello.jsp with JSP code so that
- The title of the page is Hello World Page
- It writes the string Hello World using a JSP
scriplet - This scriplet is wrapped in a ltH1gt
- - Open a browser and call the page Hello.jsp
- (e.g., http//localhost8080/ex1/Hello.jsp)
8B) Test the JSP
- - In the project exercise1.zip start Fitnesse
- - In the wiki page modify the classpath with the
path of the - fitnesse.zip in your desktop
- !path C/Documents and Settings/Desktop/fitnesse
/lib/.jar - - Complete the TestHelloWorld Fit-Table used to
verify your - HelloWord JSP as follows
note the slash
9- Fit-Table
- Get the Hello.jsp page
- Verify that it contains the string Hello World
- Verify that it contains only the string Hello
World - Verify that it doesnt contain the string The
Best Hello World - Ask the total number of HTML element of the page
- (i.e., wrapped into lthtmlgt)
- Ask the total number of HTML element wrapped
- into the body tag
- Verify that the second HTML element of the page
is of type - body tag
- Ask the number of tag H1 contained in the page
10Exercise 2 (a)
Download the zip file exercise2.zip and put it
in the desktop http//sra.itc.it/people/marchett
o/courses/trento/lsa/07/code/exercise2.zip -
Import it into Eclipse File?Import?Existing
Project into Workshopace and click next
? select Archive File ? Browser your desktop
to select the exercise1.zip ? click
Finish - In the new Eclipse project --
(if needed) create a directory called "work" if
it doesn't exist -- (if needed) delete
subdirectories of the directory "work" if it
exist and contains errors - (if needed)
Start Tomcat or restart it - open the "Tomcat
project" menu (right-button mouse in the
project) and update the Tomcat context
11Exercise 2 (b)
- Start Fitnesse for the imported project (named
nameWeb) -- remember to modify the classpath with
the path of the fitnesse.zip in your
desktop !path C/Documents and
Settings/Desktop/fitnesse/lib/.jar - Execute
the tasks described in wiki page a) bug
fixing b) maintenance c) evolution
12- NameWeb is composed of
- 1. A client side page named index.html
- it contains a form composed of 2 text fields
(name and surname) and a submit button - the form sends its data to the JSP page
- 2. A JSP page named nameWeb.jsp
- it gets name and surname sent by the client
- - it stores name and surname in a JavaBean
- it reads the data stored in the JavaBean
- it writes in output a string such as Welcome
name surname - 3. A JavaBean named beanPck.NameBean
- it defines a field of type string
- it contains two methods used to set/get the
string
13(No Transcript)
14NameWeb JSP and Form (1)
index.html
Please, insert the requested data for
JSP ltbrgt ltform method"get" action"nameWeb.jsp"
gt Name ltinput type"text" name"nameJ" /gt
ltbr /gt Surname ltinput type"text"
name"surnameJ" /gt ltbr /gt ltinput
type"submit" value"submitToJSP" /gt lt/formgt
15NameWeb Servlet, JSP and Form (3)
nameWeb.jsp
ltHTMLgt ltHEADgt ltTITLEgt JSP for name and surname
lt/TITLEgt lt/HEADgt ltBODYgt ltPgt ltjspuseBean
id"beanN" class"beanPck.NameBean" /gt lt
String namerequest.getParameter("nameJ")
String surnamerequest.getParameter("surnameJ")
beanN.setContent(name, surname) gt
ltH1gtWelcome ltIgt lt String
contentbeanN.getContent()
out.println(content) gt lt/Igt lt/H1gt
lt/BODYgt lt/HTMLgt
16NameWeb Servlet, JSP and Form (5)
beanPck.NameBean
package beanPck public class NameBean
private String content"anonymous" public
String getContent() return(content)
public void setContent(String name, String
surname) contentnamesurname
17The Fitnesse-wiki contained in the Eclipse
project to do these tasks 1) Bug
fixing There is a bug in the main
functionality of the NameWeb application. 2)
Maintenance Refactoring extract in a function
the code used to concatenate name and surname
written in the form by the user 3)
Evolution Add a field nation in the form so
that the new output will be such as Welcome
name surname from nation instead of Welcome
name surname
181) Bug fixing There is a bug in the main
functionality of the NameWeb application.
19!path fitnesse.jar !path .jar !path
lib/.jar !path classes !path lib !-com.jbergin.
HtmlFixture-! http//localhost8080/ex2/index.h
tml requestPage Focus requestPage
Element Focus nameJ input textField1
Set Value myName Focus requestPage
Element Focus surnameJ input textField2
Set Value mySurname Focus requestPage
Element Focus f_jsp form Submit
response1 Focus response1 Has Text
Welcome myName mySurname
Test case
20Before and After bug-fixing
212) Maintenance Refactoring extract in a
function the code used to concatenate name and
surname written in the form by the user
22!path fitnesse.jar !path .jar !path
lib/.jar !path classes !path lib !-com.jbergin.
HtmlFixture-! http//localhost8080/ex2/index.h
tml requestPage Focus requestPage
Element Focus nameJ input textField1
Set Value myName Focus requestPage
Element Focus surnameJ input textField2
Set Value mySurname Focus requestPage
Element Focus f_jsp form Submit
response1 Focus response1 Has Text
Welcome myName mySurname
Test case
23Before and After bug-fixing
add the new function
243) Evolution Add a field nation in the Form
so that the new output will be such
as Welcome name surname from nation instead
of Welcome name surname
25Test case
!path fitnesse.jar !path .jar !path
lib/.jar !path classes !path lib !-com.jbergin.
HtmlFixture-! http//localhost8080/ex2/indexEv
olution.html requestPage Focus
requestPage Element Focus nameJ input
textField1 Set Value myName Focus
requestPage Element Focus surnameJ input
textField2 Set Value mySurname Focus
requestPage Element Focus nationJ input
textField3 Set Value myNation Focus
requestPage Element Focus f_jsp form
Submit response1 Focus response1 Has
Text Welcome myName mySurname from myNation
26Before the evolution
27After the evolution