The current homework assignment is Homework Nine. 

It will be announced today and will be due next week.

Due Thu night late without penalty Fri 5pm.

Labs as usual next week, then Thanksgiving Week.

In lab this week:

(a) develop a JSP (or servlet, up to you) to match Homework Six

(b) develop two applets and post them in Tomcat 

Let's start creating a new context:

[tblgrant@silo 11082012]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012
[tblgrant@silo 11082012]$ mkdir WEB-INF
[tblgrant@silo 11082012]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012
[tblgrant@silo 11082012]$ mkdir WEB-INF/classes
[tblgrant@silo 11082012]$ cd WEB-INF/
[tblgrant@silo WEB-INF]$ mkdir lib
[tblgrant@silo WEB-INF]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012/WEB-INF
[tblgrant@silo WEB-INF]$ cd ../..
[tblgrant@silo webapps]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps
[tblgrant@silo webapps]$ du -a 11082012/
4       11082012/WEB-INF/classes
4       11082012/WEB-INF/lib
12      11082012/WEB-INF
16      11082012/
[tblgrant@silo webapps]$

Let's finalize our development from last time:

[tblgrant@silo 11082012]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012
[tblgrant@silo 11082012]$ ls -l
total 8
-rw------- 1 tblgrant projects  294 Nov  8 09:52 one.html
drwx------ 4 tblgrant projects 4096 Nov  8 09:47 WEB-INF
[tblgrant@silo 11082012]$ cat one.html
<html>
  <head>
    <title>
      Something simple
    </title>
  </head>
  <body>
    <form action="one.jsp">
      <table>
        <tr> <td> Name <td> <input type=text name=person>
        <tr> <td> Age <td> <input type=text name=age>
      </table>
    </form>
  </body>
</html>
[tblgrant@silo 11082012]$ pico one.html
[tblgrant@silo 11082012]$ pico one.jsp
[tblgrant@silo 11082012]$ clear
[tblgrant@silo 11082012]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012
[tblgrant@silo 11082012]$ ls -l
total 12
-rw------- 1 tblgrant projects  383 Nov  8 09:57 one.html
-rw------- 1 tblgrant projects  344 Nov  8 10:16 one.jsp
drwx------ 4 tblgrant projects 4096 Nov  8 09:47 WEB-INF
[tblgrant@silo 11082012]$ cat one.html
<html>
  <head>
    <title>
      Something simple
    </title>
  </head>
  <body>
    <form action="one.jsp">
      <table>
        <tr> <td> Name <td> <input type=text name=person>
        <tr> <td> Age <td> <input type=text name=age size=4>
      </table> <p>
      Please press <input type=submit name=action value=Proceed> to send the data.
    </form>
  </body>
</html>
[tblgrant@silo 11082012]$ cat one.jsp
<%
   String name = request.getParameter("person");
   String age = request.getParameter("age");

   try {
     age = (Integer.parseInt(age) + 1) + "";
 %>
Well, <%=name%>, you will be <%=age%> years next year.
<%
   } catch (Exception e) {
 %>
Please enter data carefully because <code>(<%=age%>)</code> is not an integer.
<%
   }
 %>


[tblgrant@silo 11082012]$

Behind every JSP there is a servlet.

We create a second simple JSP:

[tblgrant@silo 11082012]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012
[tblgrant@silo 11082012]$ cat two.jsp
<%

  out.println( "The lucky number is: " + Math.random() );

 %>
[tblgrant@silo 11082012]$


And here's the servlet that Tomcat wrote compiled and installed when I accessed the JSP first: 

[tblgrant@silo localhost]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/work/Catalina/localhost
[tblgrant@silo localhost]$ du -a 11082012/
4       11082012/org/apache/jsp/one_jsp.class
4       11082012/org/apache/jsp/two_jsp.class
4       11082012/org/apache/jsp/one_jsp.java
4       11082012/org/apache/jsp/two_jsp.java
20      11082012/org/apache/jsp
24      11082012/org/apache
28      11082012/org
4       11082012/tldCache.ser
36      11082012/
[tblgrant@silo localhost]$ cat 11082012/org/apache/jsp/two_jsp.java
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class two_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.List _jspx_dependants;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                        null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;



  out.println( "The lucky number is: " + Math.random() );


      out.write('\n');
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
[tblgrant@silo localhost]$


Next we develop a servlet:

[tblgrant@silo classes]$ pwd
/u/tblgrant/apache-tomcat-5.5.17/webapps/11082012/WEB-INF/classes
[tblgrant@silo classes]$ cat Three.java
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class Three extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
              throws ServletException, IOException {

    PrintWriter out = response.getWriter();

    out.println();
    out.println( new java.util.Date() );

  }
}
[tblgrant@silo classes]$ cat ../web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

  <servlet>
    <servlet-name>xiS</servlet-name>
    <servlet-class>Three</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>xiS</servlet-name>
    <url-pattern>/servlet/Nine</url-pattern>
  </servlet-mapping>

</web-app>
[tblgrant@silo classes]$

In class we forgot to write public next to the class Three code. 

--