Monday, November 5, 2007

25. WebAppQuestions

1. Explain in your own words the meaning of the web "request-response cycle".
Two computers want to talk to each other. One computer (the one 'requesting' data) sends a request to the other computer. The other computer sends their 'response', and the first computer receives the data they requested.

2. Explain how servlets facilitate processing of the request-response cycle.
A servlet is a class that runs within a web server. It handles the response part of the request-response cycle.

3. How do you login to the Tomcat Manager?
Go to the root page (http://localhost:8080) and use the login you configured in the box on the left.

4. What is the Tomcat Manager used for in the StackStripes application?
Nothing, because it is all done in the Ant task.

Actually, it is used for managing various different web apps that were developed for the server. Whenever an application is added or removed to the manager, it is done so using this interface (unless done via an ant task)

5. What is the directory and file layout of an installed web application like StackStripes? (This is NOT the same as the directory and file layout of the StackStripes distribution!)
It is contained as a .war file, much like a .jar file for java applications. It is more or less the same as a .jar file, with the exception that .jsp pages in the archive are stored in the root directory of the archive, which would correspond to the root folder of the web app.

6. How do you build a war directory structure in Ant? Where is this accomplished in the StackStripes application?
You type 'ant war'. This is done after compilation is done:

- copy all the files needed for the war (preserving directory structure) to a temporary folder. This is done by copying it to ./build/war. Class files are actually not copied here; but all the metadata is stored here.
- create the archive, preserving directories.

7. How do you install a war directory in a running Tomcat server? What information does the Ant task need to accomplish this?
Go to Tomcat manager, and on the bottom there is a deploy option. It can also be done in an Ant task by accessing the interface via the Ant task.

8. What is the "Model2" architecture? What are its advantages?
It is a method of representing data on a web application - Model, View, Controller. The model contains the data, the view accesses the model, and the controller sends requests to the view. The main benefit is abstraction - the controller doesn't need to know any of the internals of the model to do anything.

This sounds a lot like a database system, though, which I would guess is where the idea came from.

9. What are JSP pages? How are they related to servlets?
A JSP page is basically HTML code with special tags that allow them to access Java classes. They are related in the sense that the JSP accesses data that could be contained in a servlet.

10. Why is there a delay when retrieving a JSP page for the first time? Where is the Java code for that page stored?
For the first time, a client needs to instantiate a session with the server. The Java code for the JSP page is stored in the class.

11. What are JSTL tags? Why are they useful? What is an example JSTL tag from the StackStripes system?
Java Server Standard Tags Library - they are a common set of JSP tags that can be used among various web app frameworks. They are useful since they can be used amongst different frameworks - if you learn one, learning another isn't as difficult since it would (in theory at least) be similar to the first.

Example of JSTL tag:

since this would be independent of the framework.

12. What are Stripes tags? Why are they useful? What is an example Stripes tag from the StackStripes system?
Stripes are similar to JSTL tags except they start with "stripes:" and are only used on the Stripes framework. They are useful since it tells the framework information about the web app and the information that is passed between the controller and model.

Example Stripes tag:


13. What is HttpUnit? How is it different from JUnit? Why is it useful? What is an example use of HttpUnit from the StackStripes system?
HttpUnit is a testing framework for accessing applications via a web interface. It is different since JUnit usually accesses the objects directly; but HttpUnit tests what the user would see. It is useful since sometimes the interface is broken while the model is OK.

Example use:

// Get welcome.jsp page and check for successful retrieval
String Url = testHost + "stackstripes";
WebResponse response = conversation.getResponse(Url);
assertEquals("Checking index.jsp retrieval", pageTitle, response.getTitle());


14. What needed to be changed in order to implement the Double It button? What didn't need to be changed? What did you learn about the MVC design pattern from this exercise?
To implement the button, I added a Response function, as well as a function to the model. Most of the model could be left intact, as well as the underlying stack implementation. I learned that the response functions and model functions can correspond.

15. What are the equivalence classes that need to be tested for the Double It button?
Empty stack, 1 element in stack, more than 1 element in stack. This isn't too bad since the stack must be valid prior to the Double It button being pressed.

16. Provide two screen images of your new StackStripes application with the Double It button, one showing the page before and one showing the page after hitting the "Double It" button.




17. What is the singleton design pattern? What is an example of its use in StackStripes? Why is it needed?

It is the pattern that only one operation can be executing on the model at any given time - this is needed to deal with concurrency issues if multiple users are accessing the model at any given time. The example of its use is in the 'synchronized' keyword on each public function.

18. Some of the StackStripes tests exercise code on the "server side", while others exercise code on the "client" side. Which test classes exercise code on the "server", and which exercise code on the "client"? How does Emma deal with this to create appropriate coverage data?
TestStackActionBean: client
TestStackModel: server

Emma deals with this by testing each class's test cases, and treating each class separately.

19. Running 'ant -f junit.build.xml' results in the following target invocations: tomcat.check, tomcat.undeploy, compile, war, tomcat.deploy, junit.tool, junit.report, junit. Explain what each of these targets do.
tomcat.check: Checks if tomcat is running
tomcat.undeploy: Undeploys web app from tomcat manager if it is currently running
compile: compiles code
war: makes war archive
tomcat.deploy: Uploads web app to tomcat manager.
junit.tool: runs JUnit tests
junit.report: creates JUnit report
junit: wrapper for junit.tool and junit.report

20. (Optional) If you have experience using one or more other web application frameworks, discuss your initial reactions to Stripes. How is it similar, or different, or better, or worse than your previous experience?
I have no prior experience.

No comments: