- Examples cleanup.
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 4 Apr 2007 14:06:41 +0000 (14:06 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 4 Apr 2007 14:06:41 +0000 (14:06 +0000)
- Submitted by Takayuki Kaneko and Markus Schönhaber.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@525516 13f79535-47bb-0310-9956-ffa450edef68

webapps/examples/WEB-INF/classes/chat/ChatServlet.java
webapps/examples/WEB-INF/classes/servletToJsp.java
webapps/examples/jsp/error/err.jsp
webapps/examples/jsp/forward/forward.jsp
webapps/examples/jsp/include/include.jsp
webapps/examples/jsp/jsp2/jspx/svgexample.html
webapps/examples/jsp/sessions/carts.jsp

index f27c3c0..c74899d 100644 (file)
@@ -73,37 +73,15 @@ public class ChatServlet
         HttpServletResponse response = event.getHttpServletResponse();
         
         if (event.getEventType() == CometEvent.EventType.BEGIN) {
-            String action = request.getParameter("action");
-            if (action != null) {
-                if ("login".equals(action)) {
-                    String nickname = request.getParameter("nickname");
-                    request.getSession(true).setAttribute("nickname", nickname);
-                    response.sendRedirect("post.jsp");
-                    event.close();
-                    return;
-                } else {
-                    String nickname = (String) request.getSession(true).getAttribute("nickname");
-                    String message = request.getParameter("message");
-                    messageSender.send(nickname, message);
-                    response.sendRedirect("post.jsp");
-                    event.close();
-                    return;
-                }
-            } else {
-                if (request.getSession(true).getAttribute("nickname") == null) {
-                    // Redirect to "login"
-                    log("Redirect to login for session: " + request.getSession(true).getId());
-                    response.sendRedirect("login.jsp");
-                    event.close();
-                    return;
-                }
-            }
-            begin(event, request, response);
+            System.out.println("Begin for session: " + request.getSession(true).getId());
         } else if (event.getEventType() == CometEvent.EventType.ERROR) {
-            error(event, request, response);
+            System.out.println("Error for session: " + request.getSession(true).getId());
+            throw new ServletException("error: test message");
         } else if (event.getEventType() == CometEvent.EventType.END) {
-            end(event, request, response);
+            System.out.println("End for session: " + request.getSession(true).getId());
+            throw new ServletException("end: test message");
         } else if (event.getEventType() == CometEvent.EventType.READ) {
+            System.out.println("Read for session: " + request.getSession(true).getId());
             read(event, request, response);
         }
     }
@@ -139,6 +117,7 @@ public class ChatServlet
     protected void error(CometEvent event, HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException {
         log("Error for session: " + request.getSession(true).getId());
+        System.out.println("Error2 for session: " + request.getSession(true).getId());
         synchronized(connections) {
             connections.remove(response);
         }
@@ -151,7 +130,10 @@ public class ChatServlet
         byte[] buf = new byte[512];
         do {
             int n = is.read(buf);
+            System.out.println("Read " + n + " for session: " + request.getSession(true).getId());
             if (n > 0) {
+                System.out.println("Read " + n + " bytes: " + new String(buf, 0, n) 
+                    + " for session: " + request.getSession(true).getId());
                 log("Read " + n + " bytes: " + new String(buf, 0, n) 
                         + " for session: " + request.getSession(true).getId());
             } else if (n < 0) {
index 11af6b4..fc535bd 100644 (file)
@@ -24,7 +24,7 @@ public class servletToJsp extends HttpServlet {
        try {
            // Set the attribute and Forward to hello.jsp
            request.setAttribute ("servletName", "servletToJsp");
-           getServletConfig().getServletContext().getRequestDispatcher("/jsptoserv/hello.jsp").forward(request, response);
+           getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
        } catch (Exception ex) {
            ex.printStackTrace ();
        }
index 322f797..339d5b2 100644 (file)
@@ -24,7 +24,7 @@
 
                if (request.getParameter("name") == null) {
        %>
-       <%@ include file="/error/error.html" %>
+       <%@ include file="error.html" %>
        <%
                } else {
                  foo.setName(request.getParameter("name"));
index 4a37fd0..f7d34f9 100644 (file)
@@ -11,7 +11,7 @@
    if (percent < 0.5) { 
 %>
 
-<jsp:forward page="/forward/one.jsp"/>
+<jsp:forward page="one.jsp"/>
 
 <% } else { %>
 
index 2f2959d..706ff7e 100644 (file)
@@ -26,7 +26,7 @@
 
 <%@ include file="foo.jsp" %>
 
-<p> <jsp:include page="/include/foo.html" flush="true"/> by including the output of another JSP:
+<p> <jsp:include page="foo.html" flush="true"/> by including the output of another JSP:
 
 <jsp:include page="foo.jsp" flush="true"/>
 
index 87b6ae0..f6718fc 100644 (file)
@@ -36,8 +36,8 @@
       <li>Download <a href="http://xml.apache.org/batik/index.html">Batik</a>,
           or any other SVG viewer.</li>
       <li>Copy the following URL:
-      <a href="http://localhost:8080/jsp-examples/jsp2/jspx/textRotate.jspx?name=JSPX">
-      http://localhost:8080/jsp-examples/jsp2/jspx/textRotate.jspx?name=JSPX</a>
+      <a href="http://localhost:8080/examples/jsp/jsp2/jspx/textRotate.jspx?name=JSPX">
+      http://localhost:8080/examples/jsp/jsp2/jspx/textRotate.jspx?name=JSPX</a>
       </li>
       <li>Paste the URL into Batik's Location field and press Enter</li>
       <li>Customize by changing the name=JSPX parameter</li>
index bf9df74..c1d2721 100644 (file)
@@ -40,5 +40,5 @@
 </FONT>
 
 <hr>
-<%@ include file ="/sessions/carts.html" %>
+<%@ include file ="carts.html" %>
 </html>