Skip to main content.

Lab 5: Subversion and JSPs

Goals

After completing this lab, you should be able to

Subversion

Installing Subclipse

Subclipse Installation

Importing a Project from Subversion in Eclipse

  1. Select File → Other → SVN → Checkout Projects from SVN
  2. Create a New Repository
  3. 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.
  4. Select your project, then Next
  5. Checkout as a project with the Project Wizard.
  6. For the project type, select Web → Dynamic Web Project.
  7. Name the project something appropriate
  8. You should now have a project called "Your Project [YourProject/branches]" or something like that in your project explorer.
  9. 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

  1. In the project, create a page called yourlastname.html
  2. Add some very basic information, like a title and an h1 tag. Save the file.
  3. Right click on the file you just created.
  4. Select TeamAdd to Version Control In the project explorer, the page should now have a plus symbol over the icon, like .
  5. Right click on "WebContent" and select TeamCommit

    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.

  6. Click enter to commit the changes to the repository.

    You should get a message in the console that you were able to commit.

  7. 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.
  8. Now, if you have yourlastname.html in an editor window, close it. Then, delete yourlastname.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

  9. 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

Creating JSPs

Create a new project named Lab5.

Simple JSP (25 pts)

Next, create a simple JSP.

  1. Create a new JSP named "first.jsp", Click Next

    Select "New JSP File (html)"

  2. Add a title and a simple heading such as "My First JSP"
  3. 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.
  4. 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.
  5. Now, we'll add dynamic content to the JSP. Add a paragraph tag with the mesage "The time is now <%= new java.util.Date() %>"
  6. Reload the JSP page and see the dynamic content. Reload the page again--you should see the new current time.
  7. 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.

  8. Copy this file into your WebContent directory.
  9. Using the JSP include directive, include that file in the JSP's header (<head>).

    Make sure the Server has synchronized and reload your JSP.

  10. Modify the declaration for the date variable so that it doesn't need to say "java.util" by importing the package java.util.* using the import directive (see slides).

    Make sure the Server has synchronized and reload your JSP.

  11. 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.

  1. Create a Congratulations response in a JSP. Where should the JSP located, since it should only be accessed through a servlet?
  2. Convert the login form into a JSP.
  3. Modify your LoginServlet to, instead of generating the HTML responses, forward the request to the appropriate JSP response.
  4. Test that this is behaving correctly.
  5. 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.")
  6. Modify the login JSP to display the error message (only if the error message exists). Display the error message in an appropriate style.
  7. 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.