Exercise
2.1. In fact, the container calls the servlet's service()
method, rather than doGet()
directly. Please explain the functionality of service()
.
2.2. Please draw the UML class diagram for HttpServletRequest
and HttpServletResponse
.
2.3. Create a new Java Enterprise project named ex2.3
. Then delete the annotation in HelloServlet.java
and map this servlet to /hello
and /hi
in DD.
2.4. Based on ex2.3
, crate a new servlet MeServlet.java
, and output the content of your personal page in Exercise 1.2 through PrinterWriter
.
2.5. Please find the appropriate API from java.lang.Double
by searching Java Doc, which is capable of converting a string to double
(not the boxed Double
).
2.6. Please find the appropriate API from java.util.Arrays
by searching Java Doc, which is capable of converting an array to an ArrayList
.
2.7. Based on ex2.3
, add the line
LocalDateTime time = LocalDateTime.now();
into doGet()
method, and then output this object to the web page through PrinterWriter
.
2.8. How is the isEmpty()
method of ArrayList
implemented? Use IntelliJ IDEA to tickle your curiosity.
2.9. In Recommendation.java
of project mini-mvc
, can we replace genre.equals("novel")
with genre == "novel"
?
2.10. Please refactor Recommendation.java
by replacing if
structure with switch
.
2.11. Please add proper break line for our second version of mini-mvc
in BookServlet.java
. (Hint: using <br>
element)
2.12. The second parameter's type of setAttribute()
is Object
. Try to explain why.
2.13. Please use <ol>
and <li>
element in result.jsp
for our final version of mini-mvc
to define an ordered HTML list for the recommended books.
2.14. Try to add method="POST"
in <form>
for our final version of mini-mvc
, and then make some corresponding changes in BookServlet.java
.
2.15. Add <p>I am a paragraph</p>
in an HTML file, and then add two CSS rules:
p {
color: red;
}
p {
color: blue;
}
Which color is the <p>
? We may notice there is a conflict in CSS rules, and can you draw any conclusion?
2.16. Add <p class="special">What color am I?</p>
in an HTML file, and then add two CSS rules:
.special {
color: red;
}
p {
color: blue;
}
Which color is the <p>
? Again, there is a conflict, and can you draw any conclusion?
2.17. Try to stylish your personal home page in Exercise 1.2 by integrating with Bootstrap framework.
2.18. CodePen is an online community for testing and showcasing user-created HTML, CSS and JavaScript code snippets. Try to adapt CV Gero Zayas to create your own CV.
2.19. Try to crate an HTML page to display the same content with Office of Academic Affairs by integrating with Bootstrap framework. Note that it should contain a Navbar.
2.20. Read Chapter 3 Mini MVC Tutorial of HFBook
, and then create a new project called beer
to implement all code in MVC design. (Hint: the final code looks like Code for Servlet version three in page 89)
Optional: you can even integrate with Bootstrap framework to beautify the web pages.