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 - HUIT Sites Hosting

2: 3: www.w3.org/TR/xhtml1/DTD/xhtml1-transitional .dtd">. 4: 5: . 6: <% java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); %>. 7: <% java.io.PrintWriter pw ...

20KB Sizes 1 Downloads 317 Views

Recommend Documents

Scamazon.com - HUIT Sites Hosting
Dec 20, 2007 - project4-8.0/ directory from the course's website to your local machine. .... If your account or system ain't so happy, feel free to contact.

Wahoo! - HUIT Sites Hosting
Windows machine, you should instead execute `catalina.bat run` (assuming "%CATALINA_HOME%\bin\" is in your. PATH); alternatively ... http://127.0.0.1:n/. 10 Although you needn't type "http://" to visit most websites with most browsers these days, you

Scamazon.com - HUIT Sites Hosting
Dec 20, 2007 - an “Access Key ID” for Amazon's Web Services immediately, .... Next, proceed to edit project4-8.0/conf/server.xml with your favorite text editor.

Wahoo! - HUIT Sites Hosting
If you opt to develop on a ..... 20 Know that, during the development of this project, you can update your Javadoc by executing ... new StreamSource(new java.io.

build.xml 1/2 - HUIT Sites Hosting
7: Of course, that port cannot already be in use. Nor can it. 8: be the same value you choose for the Connector element's port. 9: 10: Also be sure to set the value ...

build.xml 1/2 - HUIT Sites Hosting
5: Computer Science E-259. 6: .... description="remove class, log, runtime, temp, and work files">. 149: ... 12: Of course, that port cannot already be in use.

build.xml 1/2 - HUIT Sites Hosting
64: call.setTargetEndpointAddress(new java.net.URL(endpoint));. 65: call.setOperationName("processPO");. 66: 67: // invoke the service and return the (PO-ACK) response. 68: return (String) call.invoke(new Object [] { poXmlString });. 69: }. 70: catch

DiagServer.java 1/2 - HUIT Sites Hosting
12: * If you spawn the server on a port already in use, you will be informed. 13: * "Server failed to start: java.net.BindException: Permission denied". 14: * Note ...

Computer Science E-259 - HUIT Sites Hosting
Nov 5, 2007 - All Rights Reserved. n-Tier Enterprise Applications. Typical J2EE Architecture. Client. Presentation. Business Logic. Data. Computer. Laptop.

SOAP 1.2 What - HUIT Sites Hosting
Apr 13, 2005 - XML with Java. Lecture 11: Web Services, SOAP 1.2, and WSDL 1.1 .... Distributed computing platforms allow programmatic components to ...

build.xml 1/1 - HUIT Sites Hosting
Login.java. 1/2 project3-8.0/src/cscie259/project3/wahoo/. 1: package cscie259.project3.wahoo;. 2: 3: import java.io.IOException;. 4: import java.io.PrintWriter;. 5: 6: import javax.servlet.ServletException;. 7: 8: import javax.servlet.http.HttpServl

Syllabus - HUIT Sites Hosting - Harvard University
Oct 15, 2007 - the form [email protected], where username is your FAS username. .... your plan at any point, provided you obtain the staff's approval for any modifications. ... Any of these texts should prove a valuable reference for.

Computer Science E-259 - HUIT Sites Hosting
Nov 5, 2007 - 22. Copyright © 2007, David J. Malan . All Rights Reserved. Java Servlet 2.5. Java Servlet Containers. ▫ Apache Tomcat. ▫ BEA WebLogic Server. ▫ IBM WebSphere Application Server. ▫ JBoss Application Server. ▫ Oracle Applicati

General Guidelines - InMotion Hosting
Mar 28, 2016 - 12.0 Understanding Mobile Users, Mobile Queries, and Mobile Results ......................................................... 56 ... 12.9 Rating on Your Phone Issues . ...... best hospitals in the U.S. Users can trust medical informati

General Guidelines - InMotion Hosting
Mar 28, 2016 - .doc or .docx (Microsoft Word). • .xls or .xlsx (Microsoft Excel). • .pdf (PDF) files. If you encounter a page with a warning message, such as “Warning-visiting this web site may harm your computer,” or if your antivirus softwa

General Guidelines - InMotion Hosting
Mar 28, 2016 - 4.3 Clear and Satisfying Website Information: Who is Responsible and Customer Service . ...... news pages, forum pages, video pages, pages with error messages, PDFs, images, gossip pages, humor pages, ... We call such.

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

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

best pdf hosting site
There was a problem loading more pages. best pdf hosting site. best pdf hosting site. Open. Extract. Open with. Sign In. Main menu. Displaying best pdf hosting ...

Best Hosting Service Provider.pdf
that offer web hosting, so you'll definitely want to do some research to find the best ones. Unlike free web hosting, you will be able to buy your own domain name ...

man-62\dedicated-hosting-india.pdf
Connect more apps... Try one of the apps below to open or edit this item. man-62\dedicated-hosting-india.pdf. man-62\dedicated-hosting-india.pdf. Open. Extract.

IPA Hosting Book_V01_Apr 2017.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. IPA Hosting ...

man-62\dedicated-hosting-provider.pdf
Connect more apps... Try one of the apps below to open or edit this item. man-62\dedicated-hosting-provider.pdf. man-62\dedicated-hosting-provider.pdf. Open.