Lab 5: Subversion and JSPs
Goals
After completing this lab, you should be able to
- Import projects from Subversion repositories.
- Use Eclipse to coordinate on source code, including doing updates, commits, adds, and deletions.
- Write simple JSPs
- Coordinate between Servlets and JSPs
Subversion
Installing Subclipse
Importing a Project from Subversion in Eclipse
- Select File → Other → SVN → Checkout Projects from SVN
- Create a New Repository
- For the URL:
- Ancient Graffiti Project:
svn+ssh://username@serac.cs.wlu.edu/svn/csrepos/graffiti/branches
Select
Spring2016
- Symbolic Logic Tutorial:
svn+ssh://username@serac.cs.wlu.edu/svn/csrepos/webapp_testing/Logic/branches
Select
LogicSpring2016
where username is your username. - Ancient Graffiti Project:
- Select your project, then Next
- Checkout as a project with the Project Wizard.
- For the project type, select Web → Dynamic Web Project.
- Name the project something appropriate
- You should now have a project called "Your Project [YourProject/branches]" or something like that in your project explorer.
- Run this project on your server. You should see the homepage.
You should be able to use this same set up for your home computer.
Using Subversion for Version Control
- In the project, create a page called
yourlastname.html
- Add some very basic information, like a title and an h1 tag. Save the file.
- Right click on the file you just created.
- Select
Team
→Add to Version Control
In the project explorer, the page should now have a plus symbol over the icon, like . - Right click on "WebContent" and
select
Team
→Commit
You should see a window that allows you to enter a comment--a note to yourself about what you have changed. You can see all the changes that were made below the comment.
- Click enter to commit the changes to the repository.
You should get a message in the console that you were able to commit.
- Everybody should now do a round of updates, using Team → Update, to get everyone's files. You should see everyone's page in the WebContent directory.
- Now, if you have
yourlastname.html
in an editor window, close it. Then, deleteyourlastname.html
file.There should be a message in your console about a file being deleted. You should also see a star on your WebContent and project directories in the project explorer, like
- Commit your changes. Depending on the timing, we will probably get conflicts that we'll need to resolve on the fly.
Version Control Lessons Learned
- It's a good idea to divide up the work so that the same people aren't working on the same files because you could get conflicts. Also, you will need to coordinate yourselves so that changes you make to one file, for example a CSS file, do not mess up the presentation of someone else's HTML file.
- Always do an
Update
before you start working so that you have the current version of the code. - Periodically, commit your changes to the Subversion repository with notes about what changes you made and why you made them.
Creating JSPs
Create a new project named Lab5
.
Simple JSP (25 pts)
Next, create a simple JSP.
- Create a new JSP named "first.jsp", Click Next
Select "New JSP File (html)"
- Add a title and a simple heading such as "My First JSP"
- Run the project on the server and view the page in a browser. The page should show up, although it may take a little while to compile the JSP into a servlet and then execute. On subsequent loads, it should be faster.
- Make a small change to, say, the heading. Then, simply reload the web page. You should see the change you made--without having to restart the server.
- Now, we'll add dynamic content to the JSP. Add a paragraph tag with the mesage "The time is now <%= new java.util.Date() %>"
- Reload the JSP page and see the dynamic content. Reload the page again--you should see the new current time.
- Create a new
Date
variable and display it.
<% java.util.Date date = new java.util.Date(); %> <p>The time is now <%= date %></p>Make sure the Server has synchronized (you'll see a message on the Server within Eclipse's console) and reload your JSP.
- Copy this file into your WebContent directory.
- Using the JSP include directive, include that file in the JSP's
header (
<head>
).Make sure the Server has synchronized and reload your JSP.
- Modify the declaration for the
date
variable so that it doesn't need to say "java.util" by importing the packagejava.util.*
using the import directive (see slides).Make sure the Server has synchronized and reload your JSP.
- Modify the JSP so that it displays "Good morning!" if the current
hour of the day is greater than 3 but less than 12, prints "Good
afternoon" if the current hour of the day is greater than or equal
to 12 and less than 17, and prints "Good night!" otherwise.
You will want to create and use a GregorianCalendar object and its methods/inherited fields to perform the above logic.
Modifying the Login Servlet (50 pts)
Modify your LoginServlet
to direct a request
to one of two JSPs.
- Create a Congratulations response in a JSP. Where should the JSP located, since it should only be accessed through a servlet?
- Convert the login form into a JSP.
- Modify your LoginServlet to, instead of generating the HTML responses, forward the request to the appropriate JSP response.
- Test that this is behaving correctly.
- Modify your LoginServlet to create an error message that is stored in the request object as an attribute. There is one error message if the username wasn't entered ("Must enter a username"), one error message if the password wasn't entered ("Must enter a password"), and one error message if the username and password don't match ("Username or password isn't correct.")
- Modify the login JSP to display the error message (only if the error message exists). Display the error message in an appropriate style.
- Test that it is behaving correctly.
Turning in the Assignment
Export the project as a .war file named "Lab5.war" and export the
source files. Copy the .war file into your turnin
directory.
Grading (75 pts)
This lab is due tonight at midnight.
- Simple JSP (25 pts)
- Login with JSPs (50 pts)