DiagServer.java examples7/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

import java.io.*; import java.net.*; import sun.net.NetworkServer; /** * A program that echoes to standard output an HTTP * request, whether GET or POST. * * Usage: java DiagServer [port] * * If you spawn the server on a port already in use, you will be informed * "Server failed to start: java.net.BindException: Permission denied". * Note that the server’s default choice of ports is 80. * * Excerpted from * http://hotwired.lycos.com/webmonkey/99/36/index3a_page4.html?tw=backend. */ public class DiagServer extends NetworkServer { public static void main(String[] args) { int port = 80; try { port = Integer.parseInt(args[0]); } catch (Exception e) { //You might want to catch a NumberFormatException here, //or do some more sophisticated command line parsing. } try { DiagServer ds = new DiagServer(); ds.startServer(port); System.err.println("DiagServer started on port " + port); System.err.println(""); } catch (IOException ioe) { System.err.println("Server failed to start: " + ioe); } } //main public void serviceRequest() throws IOException { int byteCount = 0; while (clientIsOpen() && (byteCount <1000)) { byte b = (byte) clientInput.read();

1/2

DiagServer.java examples7/ 46: byteCount++; 47: System.out.write(b); 48: System.out.flush(); 49: } 50: } //serviceRequest 51: }

2/2

get.html

1/1

examples7/ 1: 2: .dtd"> 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:


CSCI E-259
foo:
bar: 0 1
baz:
qux:
quux:



http.cgi examples7/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:

#!/usr/local/bin/perl # # http.cgi # # A Perl script that echoes the content of an HTTP request. # # Based on Steven E. Brenner’s cgi-lib.pl, available at # http://cgi-lib.berkeley.edu/. # # get request’s content type $type = $ENV{’CONTENT_TYPE’}; # get request’s content length $len = $ENV{’CONTENT_LENGTH’}; # get request’s request method $meth = $ENV{’REQUEST_METHOD’}; # read request if (!defined $meth || $meth eq ’’) { $in = $ENV{’QUERY_STRING’}; } elsif($meth eq ’GET’ || $meth eq ’HEAD’) { $in = $ENV{’QUERY_STRING’}; } elsif ($meth eq ’POST’) { if (($got = read(STDIN, $in, $len) != $len)) { die("Short Read: wanted $len, got $got\n"); } } else { die("Unknown request method: $meth\n"); } # echo content of request print <
1/1

post.html

1/1

examples7/ 1: 2: .dtd"> 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:


CSCI E-259
foo:
bar: 0 1
baz:
qux:
quux:



server.xml

1/1

examples7/base/conf/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:



web.xml

1/3

examples7/base/conf/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

default org.apache.catalina.servlets.DefaultServlet debug 0 listings true 1 jsp org.apache.jasper.servlet.JspServlet fork false xpoweredBy false 3 default

web.xml

2/3

examples7/base/conf/ 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90:

/
jsp *.jsp 0 css text/css dtd application/xml-dtd gif image/gif htm text/html html text/html jpg image/jpeg js text/javascript pdf

web.xml examples7/base/conf/ 91: application/pdf 92:
93: 94: png 95: image/png 96: 97: 98: xml 99: application/xml 100: 101: 102: xsd 103: application/xml 104: 105: 106: xsl 107: application/xml 108: 109: 110: svg 111: image/svg+xml 112: 113: 114: svgz 115: image/svg+xml 116: 117: 118: 119: 120: index.html 121: index.htm 122: index.jsp 123: 124: 125:


3/3

happyenv.jsp

1/1

examples7/base/webapps/ROOT/ 1: 2: 3: .dtd"> 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:


<% java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); %> <% java.io.PrintWriter pw = new java.io.PrintWriter(os); %> <% (new org.apache.xalan.xslt.EnvironmentCheck()).checkEnvironment(pw); %> Environment Happiness Page
 <% out.print(os); %> 


hello1.jsp

1/1

examples7/base/webapps/ROOT/ 1: 2: .dtd"> 3: 4: 5: 6: 7: 8: 9: 10: 11:


<% out.print("hello, world"); %> <% out.print("hello, world"); %>

hello2.jsp

1/1

examples7/base/webapps/ROOT/ 1: 2: 4: 5: 6: 7: ]]> 8: ]]> 9: 10: 11: 12: 13: <jsp:scriptlet> 14: out.print("hello, world"); 15: </jsp:scriptlet> 16: 17: 18: 19: 20: out.print("hello, world"); 21: 22: 23: 24: 25:

xml.jsp examples7/base/webapps/ROOT/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

String getDateTimeStr(Locale l) { DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l); return df.format(new Date()); } Example JSP in XML format This is the output of a simple JSP using XML format.
Use a jsp:scriptlet to loop from 1 to 10:
// Note we need to declare CDATA because we don’t escape the less than symbol
]]>


1/2

xml.jsp examples7/base/webapps/ROOT/ 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:

Use a jsp:expression to write the date and time in the browser’s locale: getDateTimeStr(request.getLocale())


This sentence is enclosed in a jsp:text element.



2/2

web.xml

1/1

examples7/base/webapps/ROOT/WEB-INF/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:

hello Hello parameters Parameters visits Visits hello /servlet/hello parameters /servlet/parameters visits /servlet/visits

Hello.java

1/1

examples7/base/webapps/ROOT/WEB-INF/classes/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Outputs "hello, world" in XHTML. * * @author Computer Science E-259 * * @throws IOException, ServletException */ public class Hello extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // output XHTML response.setContentType("text/html"); // grab PrintWriter PrintWriter out = response.getWriter(); // output "hello, world" in XHTML out.println(""); out.println(""); out.println(""); out.println(""); out.println("\t"); out.println("\t\tHello World!"); out.println("\t"); out.println("\t"); out.println("\t\thello, world"); out.println("\t"); out.println(""); } }

Parameters.java examples7/base/webapps/ROOT/WEB-INF/classes/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:

import import import import

java.io.*; java.util.Enumeration; javax.servlet.*; javax.servlet.http.*;

/** * Outputs parameters submitted to it via an HTTP GET. * * @author Computer Science E-259 * * @throws IOException, ServletException */ public class Parameters extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // output plain text response.setContentType("text/plain"); // grab PrintWriter PrintWriter out = response.getWriter(); // grab submitted parameters Enumeration params = request.getParameterNames(); // output each parameter’s name and value while (params.hasMoreElements()) { String param = (String) params.nextElement(); out.println(param + ": " + request.getParameter(param)); } } }

1/1

Visits.java

1/2

examples7/base/webapps/ROOT/WEB-INF/classes/ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:

import import import import import import import

java.io.IOException; java.io.PrintWriter; javax.servlet.ServletException; javax.servlet.http.HttpServlet; javax.servlet.http.HttpSession; javax.servlet.http.HttpServletRequest; javax.servlet.http.HttpServletResponse;

/** * Reports number of times a given user has visited the page in the * current session. * * @author Computer Science E-259 * * @throws IOException, ServletException */ public class Visits extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // output plain text response.setContentType("text/plain"); // grab PrintWriter PrintWriter out = response.getWriter(); // grab user parameter, else err String user = request.getParameter("user"); if (user == null) throw new ServletException("missing user parameter"); // grab current session HttpSession sess = request.getSession(); // grab user’s number of visits from session; if null, // initialize to 0 Integer visits = (Integer) sess.getAttribute(user); if (visits == null) visits = new Integer(0); // update session’s count of user’s number of visits sess.setAttribute(user, new Integer(visits.intValue() + 1));

Visits.java

2/2

examples7/base/webapps/ROOT/WEB-INF/classes/ 46: 47: 48: 49: 50: 51: }

// say hello out.println("Hey, " + user + "! " + "What’s it been, " + visits.intValue() + " time(s)?"); }

DiagServer.java 1/2 - Fas Harvard

DiagServer.java. 2/2 examples7/. 46: byteCount++;. 47: System.out.write(b); ... 2: html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

20KB Sizes 1 Downloads 300 Views

Recommend Documents

anchor.svg 1/1 - Fas Harvard
anchor.svg. 1/1 examples6/svg/. 1: 2:

foo.xml 1/1 - Fas Harvard
15: * characters are displayed as "\n", "\t", and "\r". 16: * explicitly, and line numbers are reported in errors. 17: *. 18: * @author Computer Science E-259. 19: **/.

books.xml 1/1 - Fas Harvard
2: . 3: DOCTYPE emails SYSTEM "emails.dtd">. 4: . 5:

README.txt 1/2 - Fas Harvard
3: Computer Science E-259. 4: 5: 6: OVERVIEW. 7: 8: In these directories are ... 13: * @author Computer Science E-259. 14: **/. 15: 16: public class TaxClient.

XML Schema (Second Edition) - Fas Harvard
After the release of XML 1.0, DTDs were soon recognized as insufficient. ▫ Work towards new schema standards began in early 1998. ▫ Different companies all ...

AttributeConverter1.xsl 1/2 - Fas Harvard
2/2 examples5/. 46: . 47: .... 2/2 examples5/. 44: 45: . 46: 47: . 48:  ...

Computer Science E-259 - Fas Harvard
“SVG is a language for describing two-dimensional graphics in XML. SVG allows ... Adapted from http://www.adobe.com/svg/basics/getstarted2.html. Viewable at ...

Computer Science E-259 - Fas Harvard
Computer Science E-259. XML with Java, Java ... Computer. Laptop. PDA. Web Server. JSP/servlet. JSP/servlet. EJB Server. EJB. EJB. DB. XML? ... Page 10 ...

Computer Science E-259 - Fas Harvard
Apr 13, 2005 - 1. Copyright © 2007, David J. Malan . All Rights Reserved. Computer Science E-259. XML with Java. Lecture 11:.

XML Schema (Second Edition) - Fas Harvard
Establish a contract with trading partners. ▫ Documentation. ▫ Augmentation of instance with default values. ▫ Storage of application information ...

Computer Science E-259 - Fas Harvard
Cut through the hype and get to the value. ▫ Focus on. ▫ practicality: what you need to know to do real work. ▫ applications: what are the tools and technologies.

Computer Science E-259 - Fas Harvard
Computer Science E-259. XML with Java. Lecture 5: XPath 1.0 (and 2.0) and XSLT ... All Rights Reserved. Computer Science E-259. Last Time. ▫ CSS Level 2.

Computer Science E-259 - Fas Harvard
Page 2 .... . . .... unidirectional hyperlinks of today's HTML, as well as.

XPath 1.0 (and 2.0) - Fas Harvard
Computer Science E-259. This Time. ▫ CSS Level 2. ▫ XPath 1.0 (and 2.0). ▫ XSLT 1.0 (and 2.0). ▫ TrAX. ▫ Project 2 .... Displaying XML data on the Web as HTML.

Computer Science E-259 - Fas Harvard
All Rights Reserved. Computer Science E-259. XML with Java. Lecture 2: XML 1.1 and SAX 2.0.2. 24 September 2007. David J. Malan [email protected] ...

Horario FAS Docente.pdf
TALLER DE LENGUA. Y COMUNICACIÓN I. Código 0103011. Agustín Prado. SEMINARIO DE. PENSAMIENTO LÓGICO. MATEMÁTICO. Código 0207010.

Horario FAS Docente.pdf
Rosa Chavarría. DISEÑO DE. VESTUARIO. Código 0306051. Aurora Ayala. METODOLOGÍA DE. LA DANZA III. Código 0308053. Manuel Stagnaro. KINESIOLOGÍA II. Código 0317052. Moises Del Castillo. PSICOLOGÍA. GENERAL. Código 0201050. Doris Ramírez. HOR

2017 FAS Paper Form.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. 2017 FAS Paper ...

ESTATUTO FAS 2013.pdf
Page 1 of 8. Page 1 of 8. Page 2 of 8. Page 2 of 8. Page 3 of 8. Page 3 of 8. ESTATUTO FAS 2013.pdf. ESTATUTO FAS 2013.pdf. Open. Extract. Open with.

Ciclo preparación FAS-extenso.pdf
Whoops! There was a problem loading more pages. Retrying... Ciclo preparación FAS-extenso.pdf. Ciclo preparación FAS-extenso.pdf. Open. Extract. Open with.

Fas-induced Pulmonary Apoptosis and Inflammation ...
respiratory distress syndrome (ARDS)/ALI affects about 7% of all intensive ...... system mediates epithelial injury, but not pulmonary host defenses, in response to ...