home  |  class notes  |  homework  |  jsp help  |  mysql help


Binary Search Guessing Game: Here are the JSP sources from the in-class demo in one text file: guessing-game.jsp.txt.

If you want to play the game, knock yourself out.


See the second part of this page for the files from the live demonstration in class 4/20.


Getting started with JSP.

  1. The department offers you CGI privileges (i.e. web programming privileges) along with your CS account. Avail yourself of those privileges by visiting
    https://tools.cs.uchicago.edu/activate_cgi_service
    When you register, be sure to check the button labeled "CMSC Servlets/JSP".
  2. Tomcat is a web server that runs JSP webapps, and the CS department's Tomcat server will be serving your webapps. You must now create a "Tomcat Manager" password. You can do so at the following webpage:
    https://tomcat-cmsc.cs.uchicago.edu/tomcat-manager/pwd/pwd.cgi
    This may or may not take you to the Tomcat Manager page. If so, leave the browser open there.
  3. Log on to the CS filesystem. The following folder should have been created for you:
    /stage/tomcat-cmsc/yourname
    Navigate to that folder. Create a directory called webapps inside your tomcat-cmsc folder, i.e.,
    /stage/tomcat-cmsc/yourname/webapps
    Furthermore, create
    /stage/tomcat-cmsc/yourname/webapps/index.html
    /stage/tomcat-cmsc/yourname/webapps/JSPTest/test.jsp
  4. Put the following text in the index.html you just made:
     
    <p> 
    <a href="JSPTest/test.jsp">Link to JSP test.</a> 
    </p> 
    
    
    
  5. Put this text in JSPTest/test.jsp:
     
    <p> This should be 4: <%= 5-1 %>.  </p> 
    
  6. Log in to the Tomcat Manager if you aren't already logged in:
    https://tomcat-cmsc.cs.uchicago.edu/tomcat-manager/man/manager.cgi
    In the box labeled Context Path, type
    /yourname
    In the box below and to the left of that, labeled "Directory containing WEB-INF/", type
    /yourname/webapps
    Click the "Install" button.
  7. Hopefully, that did the trick. You should see your username in the list of running webapps. Click and see if your jsp test is working. You will be able to visit and link to your webapps at the following URL:
    http://tomcat-cmsc.cs.uchicago.edu:8180/yourname/

JSP Samples from In-Class Demo

Thanks to Josh Zenker, whose files I pilfered. Don't do what I did, people!

test.jsp
<form method=POST action=greet.jsp>

<p>
Please enter your name:
<input type=text name="name">
</p>

<p>
<select name=bgc>
<option value="#FF0000">Red</option>
<option value="#00FF00">Green</option>
<option value="#FFFFFF">White</option>
</select>
</p>

<input type=submit value="CLICK WHEN READY"> 
</form>
greet.jsp
<%! class Greeter {
	private String name;
	public Greeter(String name) {
		this.name = name;
	}
	public String toHTML() {
		return "<p>Hello, " + name + "!</p>";
	}
}
%>

<% // gather form information
	String name = request.getParameter("name");
	String bgc = request.getParameter("bgc");
	Greeter g = new Greeter(name);
%>

<html>

<head></head>

<body bgcolor=<%= bgc %> >

<h1>Welcome</h1>

<%= g.toHTML() %>

<h1><%= bgc %></h1>

</body>
</html>