CS636 hw4 JPA, Intro Spring Boot webapps, tomcat (shared and embedded)
due Tues., Apr. 20 on Gradescope. (Apr. 19 is a holiday)
- Learn about JPA and Object-relational Mapping. Read Chapter
13 of Murach, and its slides, linked for the class of March 22 and 25.
See JPA2 Notes for a guide to this
chapter.
- Download and try out pizza2, the JPA version of the Pizza
Project. Note that you need need to reload the databases for
pizza2, because there’s a new table. See pizza2/README for how to
run the project. Report on any problems.
- Set up the pizza2 project in eclipse. using "Open Project from
Filesystem". Use eclipse to compare the domain packages of pizza1
and pizza2 and report on the differences, grouping similar
differences. To compare two packages, select one in the Package
Explorer, use control-click to select the other as well,
right-click and Compare With>Each Other.
- Note that this project uses Spring beans as well as JPA. This
means the *Service and *DAO objects (the singletons) are set up by
Spring based on class annotations in *Service.java and *DAO.java.
Report on the class annotations in these classes. Also verify that
PizzaSystemConfig now no longer creates these objects.
- More practice on HTTP requests. Consider the HTML on pg.
37 of Murach and here,
(/data/htdocs/cs636/ch02email/web/index.html in the filesystem)
slightly different but not enough to change these answers. This file
resides in directory ch02email (a subdirectory of the document root)
on our shared tomcat server (so its host is "localhost" when we work
on pe07) at port 8080.
- What HTTP request (first line only) happens when the user (who
is logged into pe07) browses to URL
http://localhost:8080/ch02email/emailList, the endpoint of this
servlet? What is returned by this request? Try it out with lynx.
(Let me know if the shared tomcat is down. Test it by accessing
its root URL localhost:8080).
- What HTTP request (first line only) happens when the user clicks
the submit button, shown in green by lynx? Assume user input as
shown on pg. 35 (joel@murach.com, Joel, Murach).
- What name=value pairs (known as formdata) are sent back when the
user submits the form? Where are these values in the
request?
- What HTTP request (first line only) happens at page load to
obtain the CSS for the page?
- Try out our shared tomcat on pe07 and simple JSPs without JSTL.
Tomcat is the servlet-capable web server that we will be using to
execute web applications. We now have a shared tomcat server
running on pe07.cs.umb.edu (on port 8080) for your
experimentation. Note that you need a tunnel from (say) localhost:8888
to pe07.cs.umb.edu:8080 to access this server from your browser,
similar to what you did earlier for the pizza page flow (that tomcat
was running on port 9002, and is an "embedded tomcat" serving only one
app). You can look at our shared tomcat's files at
/var/cs636/tomcat-8.5 in the UNIX/Linux filesystem. Its document root
is /var/cs636/tomcat-8.5/webapps.
- First browse to http://pe07.cs.umb.edu:8080
(http://localhost:8888 from home) to see the "root" page. You
should see a picture of a tomcat and some text about the Apache
Tomcat project. Also links, including to some JSP examples
of interest, but unfortunately written in old JSP.
- Then browse to
http://pe07.cs.umb.edu:8080/basicjsp/date_el.jsp, and see the
current date printed out, as discussed in class Monday, Mar. 10.
Then browse to http://pe07.cs.umb.edu:8080/cs636/index.html to see
my little html page. This file index.html is situated at
file path
/var/cs636/tomcat-8.5/webapps/cs636/index.html in the
Linux filesystem. You are welcome to look at it there.
Report on what this page says. Follow its link and see another
little page. The first page was served by the shared tomcat. What
server served the second page?
- Tomcat and simple JSPs with JSTL (where we see
<c:
constructs)
- Study tomcat's
/basicjstl
directory
(filesystem directory /var/cs636/tomcat-8.5/webapps/basicjstl),
including subdirectories. You will see count.jsp
and guess.jsp. Note that because these JSPs use JSTL for loop
constructs (<c:foreach) and conditional code (<c:if), they
need a WEB-INF directory with a lib directory containing the jstl
and standard jars. We didn't need these for the basicjsp files
because they only used EL and standard JSP tags like jsp:useBean.
See Chapter 6. Display the ls -lR
output (recursive
directory listing) for the basicjstl directory. Run count.jsp and
guess.jsp and report on what you see, and what HTML is sent to
your browser.
- In tomcat's
/basicjstl_broken
, find a count.jsp
that has been broken by removing the / from </c:forEach>.
Browse to it and report on the error. Explain how it points
to the bad line.
- Embedded Tomcat at home serving the ch05emailS project
- Download the ch05emailS project to your home system, build it
with "mvn package", and use "run” or "run.sh" to run it using port
9000 on your home system. This is a Spring project, but unlike
pizza2, has no singletons to set up as Spring beans. We are using
Spring Boot here for its embedded tomcat capability. Browse to
http://localhost:9000/emailList to see the form shown on pg.61.
Fill in the form and see the second page, shown on pg. 135 or pg.
137. Figure out which one it is and why and explain this in your
homework paper. The document root is (as usual for a Spring
Boot webapp) at src/main/webapp. When done, bring the app down by
using control-C for Windows or Linux or Command-C for Mac on the
run command.
- Open the project in eclipse and run it by selecting
WebApplication.java in Package Explorer, right-click, Run
As>Java Application. Report success or problems.
- Show that this tomcat can do other JSPs as well by copying
webapps/basicjsp/date_el.jsp from our shared tomcat to
webapp/basicjsp/date_el.jsp in this tomcat's area. What URL is
needed to execute it?
- Add code to the servlet and thanks.jsp to display the action
string involved in the request. Explain the edits needed for this
change.
- Running ch05emailS on pe07. Transfer the result of
problem 5 from your home system to your own cs636 directory on pe07,
and follow the README directions to run it on one of your assigned TCP
ports. Try accessing it with lynx and also be setting up a tunnel from
your home system. Report success or problems. Leave it at
cs636/ch05emailS.
- Trying out pizza3. Download pizza3.zip,
unzip it, and start an eclipse project for it.
- Run SystemTest using Oracle and runJarByProfile and note the
command used (by you and by the shell program) and success or
problems.
- Then run the web version of the project using Oracle, and order
a pizza. What URL was used to request the display of the order
form?
- Run SystemTest via its servlet by browsing to its URL. Read
SysTestServlet.java to find out the URL to use. Report the
URL and success or problems. Where did you find the output of
SystemTest in this case?