From 3a17d81b9f65359d953f477c218f0edccf6c5665 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 17 Sep 2016 17:35:24 +0800 Subject: [PATCH 01/14] final --- 1stweek/14301056.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 1stweek/14301056.py diff --git a/1stweek/14301056.py b/1stweek/14301056.py new file mode 100644 index 0000000..e69c3d3 --- /dev/null +++ b/1stweek/14301056.py @@ -0,0 +1,58 @@ +# -*- coding: utf8 -*- +# Multi Thread +import socket +import traceback +import thread + + +def ReverseString(ss): + ans = '' + l = len(ss) + while l > 0: + l -= 1 + ans += ss[l] + return ans + +def ClientServer(clientsock, clientaddr): + try: + print(clientsock.getpeername()) + while 1: + data = clientsock.recv(1024) + if not len(data): + break + print(clientsock.getpeername()), + print(': '+str(data)) + back = ReverseString(str(data)) + clientsock.sendall(back + "\n") + # clientsock.sendall("\nI get it!\n") + + except (KeyboardInterrupt,SystemExit): + raise + except: + traceback.print_exc() + try: + clientsock.close() + except KeyboardInterrupt: + raise + except: + traceback.print_exc() + +def main(): + host = '' + port = 3333 + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind((host, port)) + s.listen(1) + while 1: + try: + clientsock, clientaddr=s.accept() + except KeyboardInterrupt: + raise + except: + traceback.print_exc() + continue + thread.start_new_thread(ClientServer, (clientsock, clientaddr)) + +if __name__ == "__main__": + main() \ No newline at end of file From 2f6f8893ff542396fcc234832cb48f9e71a20fb1 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 17 Sep 2016 17:41:08 +0800 Subject: [PATCH 02/14] about 1stweek/14301056.py --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4fa3a86..b945282 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,4 @@   Multi-User using supported by Multi-Thread。 Multi-Process will be updated later。 +  <1stweek/1430156.py> The last committed file is to submit. \ No newline at end of file From 99a13de56fb22eeca07a280d7a806317fafa1238 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 17 Sep 2016 17:44:16 +0800 Subject: [PATCH 03/14] about 1stweek/14301056.py --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b945282..db5d8e2 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,4 @@   Multi-User using supported by Multi-Thread。 Multi-Process will be updated later。 -  <1stweek/1430156.py> The last committed file is to submit. \ No newline at end of file +  <[1stweek/1430156.py](https://github.com/Gusting/JavaEE-Homework/blob/master/1stweek/14301056.py)> The last committed file is to submit. \ No newline at end of file From 33a684aaf1fb77a42e190185f3dd79704caa41d9 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 17 Sep 2016 19:23:40 +0800 Subject: [PATCH 04/14] Update file --- 14301056/server.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 14301056/server.py diff --git a/14301056/server.py b/14301056/server.py new file mode 100644 index 0000000..e69c3d3 --- /dev/null +++ b/14301056/server.py @@ -0,0 +1,58 @@ +# -*- coding: utf8 -*- +# Multi Thread +import socket +import traceback +import thread + + +def ReverseString(ss): + ans = '' + l = len(ss) + while l > 0: + l -= 1 + ans += ss[l] + return ans + +def ClientServer(clientsock, clientaddr): + try: + print(clientsock.getpeername()) + while 1: + data = clientsock.recv(1024) + if not len(data): + break + print(clientsock.getpeername()), + print(': '+str(data)) + back = ReverseString(str(data)) + clientsock.sendall(back + "\n") + # clientsock.sendall("\nI get it!\n") + + except (KeyboardInterrupt,SystemExit): + raise + except: + traceback.print_exc() + try: + clientsock.close() + except KeyboardInterrupt: + raise + except: + traceback.print_exc() + +def main(): + host = '' + port = 3333 + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind((host, port)) + s.listen(1) + while 1: + try: + clientsock, clientaddr=s.accept() + except KeyboardInterrupt: + raise + except: + traceback.print_exc() + continue + thread.start_new_thread(ClientServer, (clientsock, clientaddr)) + +if __name__ == "__main__": + main() \ No newline at end of file From 37497569f5f013173cd6f6ad58dddff56190b36a Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 17 Sep 2016 19:26:54 +0800 Subject: [PATCH 05/14] about Folder-14301056 --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db5d8e2..8083e8a 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,8 @@   Multi-User using supported by Multi-Thread。 Multi-Process will be updated later。 -  <[1stweek/1430156.py](https://github.com/Gusting/JavaEE-Homework/blob/master/1stweek/14301056.py)> The last committed file is to submit. \ No newline at end of file +  <[1stweek/1430156.py](https://github.com/Gusting/JavaEE-Homework/blob/master/1stweek/14301056.py)> The last committed file is to submit. + +>14301056 + +  The Folder for Update-Homework. \ No newline at end of file From 45b53125c5ec3c442bcda2dd03d22f6a7b13d0d0 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 24 Sep 2016 19:00:49 +0800 Subject: [PATCH 06/14] upload 2ndweekhomework --- 14301056/.DS_Store | Bin 0 -> 6148 bytes 14301056/app.py | 10 +++ 14301056/server.py | 161 ++++++++++++++++++++++++++++++--------------- 3 files changed, 119 insertions(+), 52 deletions(-) create mode 100644 14301056/.DS_Store create mode 100755 14301056/app.py mode change 100644 => 100755 14301056/server.py diff --git a/14301056/.DS_Store b/14301056/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 0: - l -= 1 - ans += ss[l] - return ans + def set_application(self, application): + self.application = application -def ClientServer(clientsock, clientaddr): - try: - print(clientsock.getpeername()) + def serve_forever(self): while 1: - data = clientsock.recv(1024) - if not len(data): - break - print(clientsock.getpeername()), - print(': '+str(data)) - back = ReverseString(str(data)) - clientsock.sendall(back + "\n") - # clientsock.sendall("\nI get it!\n") - - except (KeyboardInterrupt,SystemExit): - raise - except: - traceback.print_exc() - try: - clientsock.close() - except KeyboardInterrupt: - raise - except: - traceback.print_exc() - -def main(): - host = '' - port = 3333 - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind((host, port)) - s.listen(1) - while 1: + self.connection, client_address = self.socket.accept() + self.handle_request() + + def handle_request(self): + self.request_data = self.connection.recv(1024) + self.request_lines = self.request_data.splitlines() + try: + self.get_url_parameter() + env = self.get_environ() + app_data = self.application(env, self.start_response) + self.finish_response(app_data) + print '[{0}] "{1}" {2}'.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + self.request_lines[0], self.status) + except Exception, e: + pass + + def get_url_parameter(self): + self.request_dict = {'Path': self.request_lines[0]} + for itm in self.request_lines[1:]: + if ':' in itm: + self.request_dict[itm.split(':')[0]] = itm.split(':')[1] + self.request_method, self.path, self.request_version = self.request_dict.get('Path').split() + + def get_environ(self): + env = { + 'wsgi.version': (1, 0), + 'wsgi.url_scheme': 'http', + 'wsgi.input': StringIO.StringIO(self.request_data), + 'wsgi.errors': sys.stderr, + 'wsgi.multithread': False, + 'wsgi.multiprocess': False, + 'wsgi.run_once': False, + 'REQUEST_METHOD': self.request_method, + 'PATH_INFO': self.path, + 'SERVER_NAME': self.host, + 'SERVER_PORT': self.port, + 'USER_AGENT': self.request_dict.get('User-Agent') + } + return env + + def start_response(self, status, response_headers): + headers = [ + ('Date', datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')), + ('Server', 'RAPOWSGI0.1'), + ] + self.headers = response_headers + headers + self.status = status + + def finish_response(self, app_data): try: - clientsock, clientaddr=s.accept() - except KeyboardInterrupt: - raise - except: - traceback.print_exc() - continue - thread.start_new_thread(ClientServer, (clientsock, clientaddr)) - -if __name__ == "__main__": - main() \ No newline at end of file + response = 'HTTP/1.1 {status}\r\n'.format(status=self.status) + for header in self.headers: + response += '{0}: {1}\r\n'.format(*header) + response += '\r\n' + for data in app_data: + response += data + self.connection.sendall(response) + finally: + self.connection.close() + + +if __name__ == '__main__': + port = 8888 + if len(sys.argv) < 2: + sys.exit('请提供可用的wsgi应用程序, 格式为: 模块名.应用名') + elif len(sys.argv) > 2: + port = sys.argv[2] + + + def generate_server(address, application): + server = WSGIServer(address) + server.set_application(TestMiddle(application)) + return server + + + app_path = sys.argv[1] + module, application = app_path.split('.') + module = __import__(module) + application = getattr(module, application) + httpd = generate_server(('', int(port)), application) + print 'RAPOWSGI Server Serving HTTP service on port {0}'.format(port) + print '{0}'.format(datetime.datetime.now(). + strftime('%a, %d %b %Y %H:%M:%S GMT')) + httpd.serve_forever() From 35a6c09f102c4e3c0df51726d701ceecd9dc87d4 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 24 Sep 2016 19:01:43 +0800 Subject: [PATCH 07/14] 2ndWeek --- 2ndweek/.DS_Store | Bin 0 -> 6148 bytes 2ndweek/simple_wsgi_server-master/.DS_Store | Bin 0 -> 6148 bytes 2ndweek/simple_wsgi_server-master/.gitignore | 2 + 2ndweek/simple_wsgi_server-master/app.py | 10 ++ .../simple_wsgi_server-master/middleware.py | 14 +++ 2ndweek/simple_wsgi_server-master/server.py | 115 ++++++++++++++++++ .../simple_wsgi_server-master/tornado_wsgi.py | 28 +++++ 7 files changed, 169 insertions(+) create mode 100644 2ndweek/.DS_Store create mode 100644 2ndweek/simple_wsgi_server-master/.DS_Store create mode 100755 2ndweek/simple_wsgi_server-master/.gitignore create mode 100755 2ndweek/simple_wsgi_server-master/app.py create mode 100755 2ndweek/simple_wsgi_server-master/middleware.py create mode 100755 2ndweek/simple_wsgi_server-master/server.py create mode 100755 2ndweek/simple_wsgi_server-master/tornado_wsgi.py diff --git a/2ndweek/.DS_Store b/2ndweek/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..90206a0051918f2335d3a12e107f86702b9240bc GIT binary patch literal 6148 zcmeHKyG{c^3>-s>NHi&-+aI9d4^C0|f_wlVfl#CnP!d9W9ly=^fyC)RN<{%<$vd}R zk5@Ov`3%73ulHBL48WA`h<9Jc=I8DsJE@2f>8!EF18(q!9Ue#7-v^v~!Tc4T@G{`9 zSZT+4TO4A&WX2sMd*2EIG00CB=_7@uR7AT|#WyTU$^5t=2Hm{h9~!;;Q;tGuqTPfR+jh7YTo zttJ$U+gZOwI;>07Dg~s#P=V9j&bX}!=U?)gKl8jR>=T2|c+iRZ5pZ2(Qs6ff_yEe78x;Tm literal 0 HcmV?d00001 diff --git a/2ndweek/simple_wsgi_server-master/.DS_Store b/2ndweek/simple_wsgi_server-master/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 2: + port = sys.argv[2] + + + def generate_server(address, application): + server = WSGIServer(address) + server.set_application(TestMiddle(application)) + return server + + + app_path = sys.argv[1] + module, application = app_path.split('.') + module = __import__(module) + application = getattr(module, application) + httpd = generate_server(('', int(port)), application) + print 'RAPOWSGI Server Serving HTTP service on port {0}'.format(port) + print '{0}'.format(datetime.datetime.now(). + strftime('%a, %d %b %Y %H:%M:%S GMT')) + httpd.serve_forever() diff --git a/2ndweek/simple_wsgi_server-master/tornado_wsgi.py b/2ndweek/simple_wsgi_server-master/tornado_wsgi.py new file mode 100755 index 0000000..5959b87 --- /dev/null +++ b/2ndweek/simple_wsgi_server-master/tornado_wsgi.py @@ -0,0 +1,28 @@ +# coding: utf-8 + +from __future__ import unicode_literals + +import datetime +import tornado.web +import tornado.wsgi + +from middleware import TestMiddle +from server import WSGIServer + + +class MainHandler(tornado.web.RequestHandler): + def get(self): + self.write("this is a tornado wsgi application") + + +if __name__ == "__main__": + application = tornado.web.Application([ + (r"/", MainHandler), + ]) + wsgi_app = tornado.wsgi.WSGIAdapter(application) + server = WSGIServer(('', 9090)) + server.set_application(TestMiddle(wsgi_app)) + print 'RAPOWSGI Server Serving HTTP service on port {0}'.format(9090) + print '{0}'.format(datetime.datetime.now(). + strftime('%a, %d %b %Y %H:%M:%S GMT')) + server.serve_forever() From 71a434f19f359da7d0ab143b01624de6ac3b165c Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 24 Sep 2016 19:04:43 +0800 Subject: [PATCH 08/14] about 2ndweek Folder --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8083e8a..5ec4476 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@   <[1stweek/1430156.py](https://github.com/Gusting/JavaEE-Homework/blob/master/1stweek/14301056.py)> The last committed file is to submit. +> 2ndweek + +  Simulate WSGI-Server + >14301056   The Folder for Update-Homework. \ No newline at end of file From 43f3a1e5585f192d12ee939c84bc0c622e7a7326 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sat, 24 Sep 2016 19:08:16 +0800 Subject: [PATCH 09/14] about 2nd homweek --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ec4476..f2d6eac 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ > 2ndweek -  Simulate WSGI-Server +  Simulate WSGI-Server
+ +  ```python server.py app.app 3333``` >14301056 From 6df1f2e6f654f7367051a66c1e76cb3ae42671b9 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Mon, 26 Sep 2016 23:58:26 +0800 Subject: [PATCH 10/14] add middleware --- 14301056/middleware.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 14301056/middleware.py diff --git a/14301056/middleware.py b/14301056/middleware.py new file mode 100644 index 0000000..83e4fb7 --- /dev/null +++ b/14301056/middleware.py @@ -0,0 +1,14 @@ +# coding: utf-8 + +from __future__ import unicode_literals + + +class TestMiddle(object): + def __init__(self, application): + self.application = application + + def __call__(self, environ, start_response): + if 'postman' in environ.get('USER_AGENT'): + start_response('403 Not Allowed', []) + return ['not allowed!'] + return self.application(environ, start_response) \ No newline at end of file From 0e2beae203ad19d73e2bfded358c95a66779b80d Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Tue, 27 Sep 2016 11:28:53 +0800 Subject: [PATCH 11/14] update app.py --- 14301056/app.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) mode change 100755 => 100644 14301056/app.py diff --git a/14301056/app.py b/14301056/app.py old mode 100755 new mode 100644 index 8e4a2e2..905fb27 --- a/14301056/app.py +++ b/14301056/app.py @@ -5,6 +5,10 @@ def app(environ, start_response): status = '200 OK' - response_headers = [('Content-Type', 'text/plain')] + response_headers = [('Content-Type', 'text/html')] start_response(status, response_headers) - return ['Hello world from a RAPOWSGI application!\n'] + str = environ['PATH_INFO'][1:] + print str + + # return '

Hello, %s!

' % (environ['PATH_INFO'][1:] or 'web') + # return ['Hello world from a RAPOWSGI application!\n'] \ No newline at end of file From e0a6209cc9b79d62ff891161109e78c1fe51181b Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Fri, 21 Oct 2016 20:24:10 +0800 Subject: [PATCH 12/14] 3rdweek --- 3rdweek/.DS_Store | Bin 0 -> 6148 bytes 3rdweek/TestServer/.DS_Store | Bin 0 -> 6148 bytes 3rdweek/TestServer/.classpath | 35 ++ 3rdweek/TestServer/.idea/compiler.xml | 22 + .../.idea/copyright/profiles_settings.xml | 3 + 3rdweek/TestServer/.idea/misc.xml | 42 ++ 3rdweek/TestServer/.idea/modules.xml | 8 + 3rdweek/TestServer/.idea/workspace.xml | 368 ++++++++++++++++ 3rdweek/TestServer/.project | 41 ++ 3rdweek/TestServer/.settings/.jsdtscope | 12 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../org.eclipse.wst.common.component | 8 + ...se.wst.common.project.facet.core.prefs.xml | 21 + ....eclipse.wst.common.project.facet.core.xml | 13 + ...rg.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + 3rdweek/TestServer/.tern-project | 1 + 3rdweek/TestServer/TestServer.iml | 23 + 3rdweek/TestServer/WebRoot/.DS_Store | Bin 0 -> 6148 bytes .../TestServer/WebRoot/META-INF/MANIFEST.MF | 3 + .../classes/com/dyd/test/Constants.class | Bin 0 -> 958 bytes .../classes/com/dyd/test/HttpServer1.class | Bin 0 -> 2575 bytes .../classes/com/dyd/test/LoginServlet.class | Bin 0 -> 1501 bytes .../classes/com/dyd/test/Request.class | Bin 0 -> 5432 bytes .../classes/com/dyd/test/Response.class | Bin 0 -> 3290 bytes .../com/dyd/test/ServletProcessor1.class | Bin 0 -> 2450 bytes .../dyd/test/StaticResourceProcessor.class | Bin 0 -> 740 bytes 3rdweek/TestServer/WebRoot/WEB-INF/web.xml | 25 ++ 3rdweek/TestServer/WebRoot/index.jsp | 26 ++ 3rdweek/TestServer/src/.DS_Store | Bin 0 -> 6148 bytes 3rdweek/TestServer/src/.idea/compiler.xml | 22 + .../src/.idea/copyright/profiles_settings.xml | 3 + 3rdweek/TestServer/src/.idea/misc.xml | 21 + 3rdweek/TestServer/src/.idea/modules.xml | 8 + 3rdweek/TestServer/src/.idea/src.iml | 9 + 3rdweek/TestServer/src/.idea/workspace.xml | 402 ++++++++++++++++++ 3rdweek/TestServer/src/com/.DS_Store | Bin 0 -> 6148 bytes 3rdweek/TestServer/src/com/dyd/.DS_Store | Bin 0 -> 6148 bytes .../src/com/dyd/test/Constants.java | 10 + .../src/com/dyd/test/HttpServer1.java | 76 ++++ .../src/com/dyd/test/LoginServlet.java | 44 ++ .../TestServer/src/com/dyd/test/Request.java | 289 +++++++++++++ .../TestServer/src/com/dyd/test/Response.java | 151 +++++++ .../src/com/dyd/test/ServletProcessor1.java | 48 +++ .../com/dyd/test/StaticResourceProcessor.java | 13 + 45 files changed, 1756 insertions(+) create mode 100644 3rdweek/.DS_Store create mode 100644 3rdweek/TestServer/.DS_Store create mode 100755 3rdweek/TestServer/.classpath create mode 100644 3rdweek/TestServer/.idea/compiler.xml create mode 100644 3rdweek/TestServer/.idea/copyright/profiles_settings.xml create mode 100644 3rdweek/TestServer/.idea/misc.xml create mode 100644 3rdweek/TestServer/.idea/modules.xml create mode 100644 3rdweek/TestServer/.idea/workspace.xml create mode 100755 3rdweek/TestServer/.project create mode 100755 3rdweek/TestServer/.settings/.jsdtscope create mode 100755 3rdweek/TestServer/.settings/org.eclipse.jdt.core.prefs create mode 100755 3rdweek/TestServer/.settings/org.eclipse.wst.common.component create mode 100755 3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100755 3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100755 3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100755 3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100755 3rdweek/TestServer/.tern-project create mode 100644 3rdweek/TestServer/TestServer.iml create mode 100644 3rdweek/TestServer/WebRoot/.DS_Store create mode 100755 3rdweek/TestServer/WebRoot/META-INF/MANIFEST.MF create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/Constants.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/HttpServer1.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/LoginServlet.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/Request.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/Response.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/ServletProcessor1.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/StaticResourceProcessor.class create mode 100755 3rdweek/TestServer/WebRoot/WEB-INF/web.xml create mode 100755 3rdweek/TestServer/WebRoot/index.jsp create mode 100644 3rdweek/TestServer/src/.DS_Store create mode 100644 3rdweek/TestServer/src/.idea/compiler.xml create mode 100644 3rdweek/TestServer/src/.idea/copyright/profiles_settings.xml create mode 100644 3rdweek/TestServer/src/.idea/misc.xml create mode 100644 3rdweek/TestServer/src/.idea/modules.xml create mode 100644 3rdweek/TestServer/src/.idea/src.iml create mode 100644 3rdweek/TestServer/src/.idea/workspace.xml create mode 100644 3rdweek/TestServer/src/com/.DS_Store create mode 100644 3rdweek/TestServer/src/com/dyd/.DS_Store create mode 100755 3rdweek/TestServer/src/com/dyd/test/Constants.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/HttpServer1.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/LoginServlet.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/Request.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/Response.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/ServletProcessor1.java create mode 100755 3rdweek/TestServer/src/com/dyd/test/StaticResourceProcessor.java diff --git a/3rdweek/.DS_Store b/3rdweek/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8f770946184aecf545cdbf81749f5df8f74bade8 GIT binary patch literal 6148 zcmeHKJ8r^25S;-EL>fxUy+UrVLgoa{0VoosiHzhVu3d31j>emh5XexZNQ2%;GjDfx z-dcWz$0H)T{e6EGS&PULZYW0!Q?qmPiOn*jKsfGb@EB1K!*o^q+ zxWyChaf2P7w{N?rPg7J1NC7Dz1*Cu!_)P)UY`4WlqDCno1*E{20{(qybjMyeB*v$M zL$m@fPW@ zo~Tg@NP)2evs^B{{$JC7=>Nwgt)zey_*V+pe7#w(_)1kKiZ*L=?XUN|HMo$;U(^)ukQ$fUquD{utK#u(`U literal 0 HcmV?d00001 diff --git a/3rdweek/TestServer/.classpath b/3rdweek/TestServer/.classpath new file mode 100755 index 0000000..a95193d --- /dev/null +++ b/3rdweek/TestServer/.classpath @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdweek/TestServer/.idea/compiler.xml b/3rdweek/TestServer/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/3rdweek/TestServer/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/.idea/copyright/profiles_settings.xml b/3rdweek/TestServer/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/3rdweek/TestServer/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/3rdweek/TestServer/.idea/misc.xml b/3rdweek/TestServer/.idea/misc.xml new file mode 100644 index 0000000..8d8dc8d --- /dev/null +++ b/3rdweek/TestServer/.idea/misc.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/.idea/modules.xml b/3rdweek/TestServer/.idea/modules.xml new file mode 100644 index 0000000..7047862 --- /dev/null +++ b/3rdweek/TestServer/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/.idea/workspace.xml b/3rdweek/TestServer/.idea/workspace.xml new file mode 100644 index 0000000..fff34dc --- /dev/null +++ b/3rdweek/TestServer/.idea/workspace.xml @@ -0,0 +1,368 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1477051260616 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/.project b/3rdweek/TestServer/.project new file mode 100755 index 0000000..0ab11f4 --- /dev/null +++ b/3rdweek/TestServer/.project @@ -0,0 +1,41 @@ + + + TestServer + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/3rdweek/TestServer/.settings/.jsdtscope b/3rdweek/TestServer/.settings/.jsdtscope new file mode 100755 index 0000000..2fc9dba --- /dev/null +++ b/3rdweek/TestServer/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/3rdweek/TestServer/.settings/org.eclipse.jdt.core.prefs b/3rdweek/TestServer/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..c537b63 --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/3rdweek/TestServer/.settings/org.eclipse.wst.common.component b/3rdweek/TestServer/.settings/org.eclipse.wst.common.component new file mode 100755 index 0000000..d4bf8c2 --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100755 index 0000000..2c3fdd1 --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.xml b/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100755 index 0000000..92a5a99 --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.container b/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100755 index 0000000..3bd5d0a --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.name b/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100755 index 0000000..05bd71b --- /dev/null +++ b/3rdweek/TestServer/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/3rdweek/TestServer/.tern-project b/3rdweek/TestServer/.tern-project new file mode 100755 index 0000000..b71c685 --- /dev/null +++ b/3rdweek/TestServer/.tern-project @@ -0,0 +1 @@ +{"ide":{},"libs":["ecma5","browser"],"plugins":{"guess-types":{}}} \ No newline at end of file diff --git a/3rdweek/TestServer/TestServer.iml b/3rdweek/TestServer/TestServer.iml new file mode 100644 index 0000000..5b6bd4c --- /dev/null +++ b/3rdweek/TestServer/TestServer.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/WebRoot/.DS_Store b/3rdweek/TestServer/WebRoot/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5227386424a55dc7cbbc55f1ec67cde8d421b6e6 GIT binary patch literal 6148 zcmeHKJxc>Y5PhQo18GvG+&^I9KUj_=kj5rOS_{EOA_!VvyHD(@GDf8Hjvel?ec!(xpI;``mlMvt!2uf# zxc$yQKIN^KY063gDIf);fE17dzf{0`FKxa^RFnczKni>*;NOQvckG2@VthInVgw-0 zm=5DQW(i{R1hE&6iOkR}sl=pOjTn}6=3CYE!Z9)Fuo^zBo@_OtSUjEgwRTO1i^EJAfC|1UV=>#xe%aZbojvEw+4=qF$1eao*wrw>FmL%i(;nKU5`i-JeJ@blQ-Ov_ zhM6ON%uSbjU9-_S5|(1n-_`a$95xy)hC==Px~Zh&bu08Fyl>VH+x1#2uG6cQ>v)dZ zWk?lEZHCEx-xeAShK0)rdjrR{h14-kRD(dsvhBz$W>C;@^@5=0Fi@gr;2LHba$TVg zq~8}(4H-6zB`h;&$J`x=#>Y#LBQGk6kU88ia1$#G>1y2c zT#}r225Y#bVV%Ko7L6 zqN7B;d=?$)`zpk{XW%}z$zkP>K8|6wn9xoJ45oo8q;)(bdc`Fft>Y2FSuPI(5ridA z3}~U~eBJTH+d;1*WQ%uP5srv&aktH-6P}}F7Ad?4Ey~a!s83G7uvkx?K^muQ(;rAn zgw8Nb|DVosXc^XtJ4K^BLBB;BX}1&#i84BLgxa!n`Vv(E^`FSSFI+i8{tR=cxc&{R zC%9cG(sF{W?HFBL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xpq8J!mfK`?V95Gp~ zBT+qeH82{Z(mYElDh4Q3ibc{38BraFs#ORhmQ@aSEqB-Npo%SyuMa#6suxI>PF|x= z^31GFmrErwPA#-M{;bUEgSpj{1^1SWl?BURS0zkoie)}368aivnc$@oZv!eNq?Z50dy0u{+SM zM+rXD*v@(Nlh)FCt8mYbNM?p_!L`=mU!nIsek7p8wdu(|Ek>#5hDc08U3Q#N2E9sk zNxlb0I`^((*LZ*84tDapKl#)uK5}AL|4(6!aIk9?1MdkXy+up!qkQFD3PW^mnC6X8 z>VE9Q!&>8TD79kv0QabymOU4D?x&4Cboc<-kqkOR+r)!hYvtP9Z*cHh zS3B3x)YRr@-?-X;9%Vh{8wT;s|fqMpP& z<21xre46``Iud-}r%}liM2fH!uB(r+`(#x#$KiG01GEa2*U#XyVZ10IBtk;xDb9k) z7z+}SodQq6j*v(BRz#~sp4Z5paJ7=n1Qv8Q1+vI-O)4yIXhzky;t8V_ixnc*M_x4| zm*8ylyyX|#k}ChN8<97g(3v$NpGJP8&YEaDMq~j+#>l08NlF-N5G&Uxqtt}mWh3&L zCXmk>kzNx~e%^@m5j2d|i$-KQ#;RKlBK3+{bUN-BC42#2jAB^dkDoR0<4aBC{^v&R&*97e2WRgZWjxh^(pM|1ct7Z36i(Bl6o#ApdPdeg~H#YmexA1`yT$O*dTZv#Na?|0@vnZK85v zeiyGrB2H3->iB9zv}qB0!^IjA1mHGa=eZPkgZ5PKl<(;pRoAl34J><$jYL)0+yA@Z tiEYLJy@l`B$T&qqm7g`uh3Jhry4IGcMq&X!AVz)N#t-=v_>msn`7b7Xwx|FA literal 0 HcmV?d00001 diff --git a/3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/Response.class b/3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/Response.class new file mode 100755 index 0000000000000000000000000000000000000000..1604611b57fe69f689c4da19bdcfc3fe576b15de GIT binary patch literal 3290 zcmb7F-%}e^6#i}!vJgTGEwlx#&?+_oN(!Z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my50=TgmN}S5`b^ceyo-Cxsiw(Uo^r+q;$EtYk;lgW zz*wn^VWF@;g9CgUbuBkpY?tptOPu!@ifW3imwlaaHH5dI*M-&g>a+T=HMTZ$hU_=e4)5_tVn$F EF98Ty;s5{u literal 0 HcmV?d00001 diff --git a/3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/ServletProcessor1.class b/3rdweek/TestServer/WebRoot/WEB-INF/classes/com/dyd/test/ServletProcessor1.class new file mode 100755 index 0000000000000000000000000000000000000000..2fb030d88a51052b15525ea9a0dfe4f57d998d3e GIT binary patch literal 2450 zcmai0U2_vv7=BKhj}mJ&czOt2!gKruAfw1J8Wn`B!8$!^%)Kzz+uQ_-8g^oY8Lb)avR$T7Vj}Z0 z;hbxi&9!tCy97ishB)?0>}kWq7t!zv_6hV?bjO`HOU8P3RbV91ZE9j(SvjC#3?p(cGp?DM% z0^!wi#Yn|)1XHS7NB@YCxI|K5v<u5NElZ4{x+_@XMxy5{DZt2Ei zHoK&X-G!j?cS^$>c#~M`wVGj;1g5vbr%N{oKCMig*6_9}SJbuq%wjl%w94a*z)WB+ zz$x8jDWC*=8Zh+gMcph_4BKmzam*-F?=pkLbzi$_Yl3*Zhgpep?Zw}4T%)Steavwf ztU707#8)g^$t&y~*Z0EUFW|JqMS)=t8?xuKbL&N;=9VophD*pue9*#eQPyx-m5DPz zdld?gBdg&GK4kw?*au!i2ps+&G(9l}l2d`ON@FjJ9?+q;-{FnF!)nnQnj08IL5`%SP>Yu*MsJ0m(XIYaq@ zoU0e_T-Iyer6KVZUA8TxX6*%HIje3Ljq_Y^^poqn&5o%Qa1g8xuRx%OCtg>4N`58z z7JP>%HxYf}v15EHHqg&MK=TFo9^jY2Hf-mU%00))?<4K;R0BH}rl*HS8`vGX*}(o( zNTk9d6?um7mC)}vw9@;G5Ah5~R)!Lrn0$)q23~LAt$1V;soW;sNrfL_M=J6ZXXB9u z&Nnbm^>{cQYG5H1Q9P-5vVld9CzaUppSYfqaXEGLSA5coM;J>*l~l9=ol;7x`Ca1o z6NE5|Ib7sgx&|F3ZUqEZaDhu`A>N1}!`-14w}j52PsFk$?H zJN%W>OK(4+!jp>kM^s^w7pE-?HP+@5?cIgV(={$chn^#hLec81i;GjZhx}yWQwQxjpx`1b>mwygqRV=RVf5?W)$xMdHi<4GaBnX7a#K8zS`EQeSkEc!uclYBn8xCzLiO`-DRZ1m9wkl3on#5GX3B+8j?msH?JQ}{>7m-!-j8FXfKIvlO ztK)6_-RW+@g>~@q_&ESI{^O;w4LM5K6Z`4yTSV9XI%Zp30|DmP)=L2U21kTPm}grg zU$PI_H+F8Y@C(u5+Z(j5Jv?AQn=2M%O%LL?g^0gdCYtla+huY^%rtn4XFj`uRXk^< Z5hGq;jd@-&55MCBW(^p!&S4F&9smg&sww~g literal 0 HcmV?d00001 diff --git a/3rdweek/TestServer/WebRoot/WEB-INF/web.xml b/3rdweek/TestServer/WebRoot/WEB-INF/web.xml new file mode 100755 index 0000000..2144564 --- /dev/null +++ b/3rdweek/TestServer/WebRoot/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + TestServer + + JAX-RS Tools Generated - Do not modify + JAX-RS Servlet + com.sun.jersey.spi.container.servlet.ServletContainer + 1 + + + JAX-RS Servlet + /jaxrs/* + + + + LoginServlet + + com.dyd.test.LoginServlet + + + LoginServlet + + /TestServer/LoginServlet + + \ No newline at end of file diff --git a/3rdweek/TestServer/WebRoot/index.jsp b/3rdweek/TestServer/WebRoot/index.jsp new file mode 100755 index 0000000..0866042 --- /dev/null +++ b/3rdweek/TestServer/WebRoot/index.jsp @@ -0,0 +1,26 @@ +<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + + My JSP 'index.jsp' starting page + + + + + + + + + + This is my JSP page.
+ + diff --git a/3rdweek/TestServer/src/.DS_Store b/3rdweek/TestServer/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0a8bc21eef2735eaef7786d6a2b9eb2fa2ef83ae GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHLgIFQCa5J>7ddY*ootW$?2Jc0B^niaeI z6+0^cw*P#40VV(&x+``bW@gM+IOC4%*XiSSx!>Md@hb2XF*8;s%=T+rA_5{H0wN#+ zBCsF=d5UB6yr5^&qlkbAEQ5f59~#}YmyXo + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/.idea/copyright/profiles_settings.xml b/3rdweek/TestServer/src/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/3rdweek/TestServer/src/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/.idea/misc.xml b/3rdweek/TestServer/src/.idea/misc.xml new file mode 100644 index 0000000..880e17b --- /dev/null +++ b/3rdweek/TestServer/src/.idea/misc.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/.idea/modules.xml b/3rdweek/TestServer/src/.idea/modules.xml new file mode 100644 index 0000000..f669a0e --- /dev/null +++ b/3rdweek/TestServer/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/.idea/src.iml b/3rdweek/TestServer/src/.idea/src.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/3rdweek/TestServer/src/.idea/src.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/.idea/workspace.xml b/3rdweek/TestServer/src/.idea/workspace.xml new file mode 100644 index 0000000..1cb4535 --- /dev/null +++ b/3rdweek/TestServer/src/.idea/workspace.xml @@ -0,0 +1,402 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1477041583000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/3rdweek/TestServer/src/com/.DS_Store b/3rdweek/TestServer/src/com/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6521d009eaa5f82704d833f66bf573fa878e57fb GIT binary patch literal 6148 zcmeH~J!->15QX2wE(~c@y4=PG$PE_boWK`IAxIN!FeH#}kDfO_P2|)@gf}qrc4jq5 z`UQ7hnRgqr2kZVPVF6gBjnLzs|SI$My2gidTWBh?%i6VXyYf`_SmFy>z6;r-LCz0P2?IFs@^kpf)d1d+A7Jg=RH9 zShZS=AzqJmYOCvd=}66XSPdUmcQ&75XqN4;#)M`)L_q{ZU_oG$`Q+#SEB&wef6<~; z1VrGU5wPv)d^+-_>TJDxJ+Hr2)z^bgjmsH+{RA-aqj*mb<9_o6wU>@mR%rSW2n-4$ H@K6Fjpd}HC literal 0 HcmV?d00001 diff --git a/3rdweek/TestServer/src/com/dyd/.DS_Store b/3rdweek/TestServer/src/com/dyd/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a2eb533abf551d042629249e6fe5fb378b3b5ee0 GIT binary patch literal 6148 zcmeH~u?oUK42Bc!Ah>jNyu}Cb4Gz&K=nFU~E>c0O^F6wMazU^xC+1b{XuyJ79K1T}(S!u1*@b}wNMJ-@TJzTK|1JE}{6A`8N&+PC zX9Tp_belC^D(=>|*R%RAs index1) + return requestString.substring(index1 + 1, index2); + } + return null; + } + //��InputStream�ж�ȡrequest��Ϣ������request�л�ȡuriֵ + public void parse() { + // Read a set of characters from the socket + StringBuffer request = new StringBuffer(2048); + int i; + byte[] buffer = new byte[2048]; + try { + i = input.read(buffer); + } catch (IOException e) { + e.printStackTrace(); + i = -1; + } + for (int j = 0; j < i; j++) { + request.append((char) buffer[j]); + } + System.out.print(request.toString()); + uri = parseUri(request.toString()); + } + @Override + public AsyncContext getAsyncContext() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getAttribute(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getAttributeNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getCharacterEncoding() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getContentLength() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getContentType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public DispatcherType getDispatcherType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getLocalAddr() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getLocalName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getLocalPort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Locale getLocale() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getLocales() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getParameter(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getParameterMap() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getParameterNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getParameterValues(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProtocol() { + // TODO Auto-generated method stub + return null; + } + + @Override + public BufferedReader getReader() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRealPath(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRemoteAddr() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRemoteHost() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getRemotePort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public RequestDispatcher getRequestDispatcher(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getScheme() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getServerPort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public ServletContext getServletContext() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isAsyncStarted() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isAsyncSupported() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isSecure() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void removeAttribute(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setAttribute(String arg0, Object arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void setCharacterEncoding(String arg0) + throws UnsupportedEncodingException { + // TODO Auto-generated method stub + + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + // TODO Auto-generated method stub + return null; + } + + @Override + public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) + throws IllegalStateException { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getContentLengthLong() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/3rdweek/TestServer/src/com/dyd/test/Response.java b/3rdweek/TestServer/src/com/dyd/test/Response.java new file mode 100755 index 0000000..45b42ec --- /dev/null +++ b/3rdweek/TestServer/src/com/dyd/test/Response.java @@ -0,0 +1,151 @@ +package com.dyd.test; + +import java.io.OutputStream; +import java.io.IOException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.File; +import java.io.PrintWriter; +import java.util.Locale; + +import javax.servlet.ServletResponse; +import javax.servlet.ServletOutputStream; + +public class Response implements ServletResponse{ + private static final int BUFFER_SIZE = 1024; + Request request; + OutputStream output; + PrintWriter writer; + + public Response(OutputStream output) { + this.output = output; + } + + public void setRequest(Request request) { + this.request = request; + } + //��web�ļ�д�뵽OutputStream�ֽ����� + public void sendStaticResource() throws IOException { + byte[] bytes = new byte[BUFFER_SIZE]; + FileInputStream fis = null; + try { + /* request.getUri has been replaced by request.getRequestURI */ + File file = new File(Constants.WEB_ROOT, request.getUri()); + fis = new FileInputStream(file); + /* + * HTTP Response = Status-Line(( general-header | response-header | + * entity-header ) CRLF) CRLF [ message-body ] Status-Line = + * HTTP-Version SP Status-Code SP Reason-Phrase CRLF + */ + int ch = fis.read(bytes, 0, BUFFER_SIZE); + while (ch != -1) { + output.write(bytes, 0, ch); + ch = fis.read(bytes, 0, BUFFER_SIZE); + } + } catch (FileNotFoundException e) { + String errorMessage = "HTTP/1.1 404 File Not Found\r\n" + + "Content-Type: text/html\r\n" + "Content-Length: 23\r\n" + + "\r\n" + "

File Not Found

"; + output.write(errorMessage.getBytes()); + } finally { + if (fis != null) + fis.close(); + } +} + + @Override + public void flushBuffer() throws IOException { + // TODO Auto-generated method stub + + } + + @Override + public int getBufferSize() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getCharacterEncoding() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getContentType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Locale getLocale() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public PrintWriter getWriter() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isCommitted() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void reset() { + // TODO Auto-generated method stub + + } + + @Override + public void resetBuffer() { + // TODO Auto-generated method stub + + } + + @Override + public void setBufferSize(int arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setCharacterEncoding(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setContentLength(int arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setContentType(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setLocale(Locale arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setContentLengthLong(long l) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/3rdweek/TestServer/src/com/dyd/test/ServletProcessor1.java b/3rdweek/TestServer/src/com/dyd/test/ServletProcessor1.java new file mode 100755 index 0000000..86113b6 --- /dev/null +++ b/3rdweek/TestServer/src/com/dyd/test/ServletProcessor1.java @@ -0,0 +1,48 @@ +package com.dyd.test; + +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLStreamHandler; +import java.io.IOException; +import javax.servlet.Servlet; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +public class ServletProcessor1 { + public void process(Request request, Response response) { + String uri = request.getUri(); + String servletName = uri.substring(uri.lastIndexOf("/") + 1); + + //ڴָJARļĿ¼ + URLClassLoader loader = null; + try { + URLStreamHandler streamHandler = null; + // + loader = new URLClassLoader(new URL[]{new URL(null, "file:" + Constants.WEB_SERVLET_ROOT, streamHandler)}); + } catch (IOException e) { + System.out.println(e.toString()); + } + + Class myClass = null; + try { + //ضӦservlet + myClass = loader.loadClass(servletName); + } catch (ClassNotFoundException e) { + System.out.println(e.toString()); + } + + Servlet servlet = null; + + try { + //servletʵ + servlet = (Servlet) myClass.newInstance(); + //ִervletservice + servlet.service((ServletRequest) request,(ServletResponse) response); + } catch (Exception e) { + System.out.println(e.toString()); + } catch (Throwable e) { + System.out.println(e.toString()); + } + + } +} diff --git a/3rdweek/TestServer/src/com/dyd/test/StaticResourceProcessor.java b/3rdweek/TestServer/src/com/dyd/test/StaticResourceProcessor.java new file mode 100755 index 0000000..e1efbf6 --- /dev/null +++ b/3rdweek/TestServer/src/com/dyd/test/StaticResourceProcessor.java @@ -0,0 +1,13 @@ +package com.dyd.test; + +import java.io.IOException; +public class StaticResourceProcessor { + public void process(Request request, Response response) { + try { + response.sendStaticResource(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} From 26c80b748d03df9123b90b04bf5733ca8b6085ef Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sun, 23 Oct 2016 11:15:17 +0800 Subject: [PATCH 13/14] jsp --- 4thweek/bin/jsp/Constants.class | Bin 0 -> 922 bytes 4thweek/bin/jsp/HttpServer.class | Bin 0 -> 5947 bytes 4thweek/bin/jsp/Request.class | Bin 0 -> 4509 bytes 4thweek/bin/jsp/Response.class | Bin 0 -> 3365 bytes 4thweek/bin/jsp/ServletProcessor.class | Bin 0 -> 2429 bytes 4thweek/bin/jsp/StaticResourceProcessor.class | Bin 0 -> 677 bytes 4thweek/bin/jsp/jspReader.class | Bin 0 -> 5516 bytes 4thweek/part/part_1.txt | 11 + 4thweek/part/part_2.txt | 5 + 4thweek/part/part_3.txt | 25 ++ 4thweek/part/part_4.txt | 7 + 4thweek/src/jsp/Constants.java | 11 + 4thweek/src/jsp/HttpServer.java | 254 ++++++++++++++++++ 4thweek/src/jsp/Request.java | 188 +++++++++++++ 4thweek/src/jsp/Response.java | 115 ++++++++ 4thweek/src/jsp/ServletProcessor.java | 56 ++++ 4thweek/src/jsp/StaticResourceProcessor.java | 15 ++ 4thweek/src/jsp/aa.java | 0 4thweek/src/jsp/jspReader.java | 193 +++++++++++++ 19 files changed, 880 insertions(+) create mode 100755 4thweek/bin/jsp/Constants.class create mode 100755 4thweek/bin/jsp/HttpServer.class create mode 100755 4thweek/bin/jsp/Request.class create mode 100755 4thweek/bin/jsp/Response.class create mode 100755 4thweek/bin/jsp/ServletProcessor.class create mode 100755 4thweek/bin/jsp/StaticResourceProcessor.class create mode 100755 4thweek/bin/jsp/jspReader.class create mode 100755 4thweek/part/part_1.txt create mode 100755 4thweek/part/part_2.txt create mode 100755 4thweek/part/part_3.txt create mode 100755 4thweek/part/part_4.txt create mode 100755 4thweek/src/jsp/Constants.java create mode 100755 4thweek/src/jsp/HttpServer.java create mode 100755 4thweek/src/jsp/Request.java create mode 100755 4thweek/src/jsp/Response.java create mode 100755 4thweek/src/jsp/ServletProcessor.java create mode 100755 4thweek/src/jsp/StaticResourceProcessor.java create mode 100755 4thweek/src/jsp/aa.java create mode 100755 4thweek/src/jsp/jspReader.java diff --git a/4thweek/bin/jsp/Constants.class b/4thweek/bin/jsp/Constants.class new file mode 100755 index 0000000000000000000000000000000000000000..06d2187c560e800f1c540e1d4075673d8c568cb9 GIT binary patch literal 922 zcmZuvU2hUW6g^W~c7bWBSgf_$TB{XMS+#ycjA=uCA<`6r@yQG@;*#wynH`$+$={?V zZKH`lz#nD2v!D%ym%Tgp-Z|&oGxztOAHM)>qikV@VZImko!!6>weWRlVU}UBCys>U z3BT*qT0Pm;4EFoV&c}mVt-+9~o|o%dxqi1qS4_QLIcQcZjZvRnZhNlp>emdhT)xRL zyBl<*1@Dj z9+|3x;af2*<)%!K0HJftA#TGVMlBS1YvU2Q(e^|b%FwiIb67@ay6XD!-Qch#RYSBq zX|^J03$H1ZYtB(Ji5Q+6R}%F0`m-CFdt=*1i<7Je1J#zs1BQkFdssB)V1p=Qw5v1p zE+mcqRt$fXv0=kVO48{|)CIi#iPVS8{29_`$ev>L8`e*7`vke~xIeX&DN=pdm3jED z_3_t;;0b-#hz>-UrkJI;N~8s%eM51N;?t-TB!i|LiE$`0%Fh)}@$4KbK1@be_~`!y MUQ#2&s|cp_7xsnES^xk5 literal 0 HcmV?d00001 diff --git a/4thweek/bin/jsp/HttpServer.class b/4thweek/bin/jsp/HttpServer.class new file mode 100755 index 0000000000000000000000000000000000000000..2bb99773c88a4aedfe42aeed3350e02a9c381907 GIT binary patch literal 5947 zcma)A33yc175;BBnK#SJLSQ0KaRCIAunZu^I#G~SL$g@IVsM>IUSMD{Gt9gYC~aLD z7p#c2?$y?%n%Y`L(Me(~)E%{2wN|UO+A5;m)Y@vXwx<8R?@cm;srV7z%)R&AbIv{I zKmWOJp8D*8od9MFLqmZ;$=Y->c(P?Bo6Xb)Go`^LP_{O_Asmc_9W>D z({!pn-+9`1b%djFfr`r0KJQ)C3Lki2`8Y_&SZS{)+!c=Uc&>12H5HB?VHcfFJE1vL zAfV11H?5!@ujWK#ooRV+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QXz9&aH|mhc7ABfP{qxq8G3;5k%A?}RmremV2T`Naitl0$lF~k0>uVls9?3b+b04(!{ZDu7a?C^jlT!g zhBrVPQl&mxlt}rkaa|6mGUV&_i-6xC^p&dTgah*q`kjUOXi=7n^Cmfvj+YeHl=fh@ zQ4%P%t&~YCWy4k~44)hhyIvCVcbAGlsXUOf_qbgkS=YC!606E7vC*PD*S6m&v4;G@ zdcFrfnS%^&n7W-w42V0#okNuTI4KvT!UB?@i!drB@s*Q-0wleINqFN)dDSGjStPX( zN$dm?*8&n+BWdOg!n_?jS$4b7g@rp%0*px8$nal0ZQ=1?3&lop7w{{!oW?QH-6 literal 0 HcmV?d00001 diff --git a/4thweek/bin/jsp/Request.class b/4thweek/bin/jsp/Request.class new file mode 100755 index 0000000000000000000000000000000000000000..a7b708c7fc52fb3d78e5149baf809934d6b39bff GIT binary patch literal 4509 zcmb7GYjYGu6g|D!u*qhCLIYgkOU!uL?Ve<2x3H?>^8}S&CD`88^IU8 z-|y!KtF*MN;)_=KB9xEv2l#9J0hD;UXEHlsCzYirc4oToIeqTEr@Qmde}DW9U?;vv zAtBH*Q!Zu4%2%_F;{-oa~Sq$a$_bXZHy-R9s8oCVy6QbIP)(IJKhBvMp~wV10KixMy4-Ip`E* z8Vy)&pareu>+TtE1{n>c&?K;W*s|rZ%Iu_ckDHT4sn&AxW^vqfE%hA?CcSB^EUYslpc_2`&E?8uS(i>=otmxH%lurwpZ+q;Pp@!~ zfEZf%*ukirXXej7VwQs9H0s<^VBET@2Yil$l{06go5ptRR2{h2*E*iYZrqo`9)UG6 zeK&AF_A-(lD5zW}4yx?>Fpxrj6ftt>d|sA3%drjYSKVD*qBm$B$~*3wd3Js~4j4Fy zLCQBvC25myWA|Wf^1jY}%{YXIQaHT0=oiYKoHcL+tU`mc*si1girTJfxuXV#v7Qb0 z9KQl-9K&b|BN5>djDbfn#vHY9Zi6^)uv!Ag4Qxawn;x`?wy)`6kObRBORkvIr58v{ z9OMX{9ob{m%F)GQC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100755 index 0000000000000000000000000000000000000000..c72073d051fde3f0aea058062e0a09f5d4ccbadd GIT binary patch literal 677 zcmaJVEb$+C=7I?a zetMA>JRAcfJU6&J^>(92#bzPS> zL?BomsVkL@Rq-V|9*%V02o_$O!ZdFLb9?&(LGZRb*D>a>m|z|Yf~CGG^wH#EsO^~= zjC~F*UFN5Z*sRf(;|48Tw!fL8Vu(jt?PxR$P*G;blbyXI%?(Gj^Jitnb zt{`!Y9LGlzJanSEwJy$Q2aU0Y#~~gGR{W5r%sw8!`=0BnF=dh9i65r2rf680e><}( z=P;q23J|0-dIXVedkXH)suKt+SNs3y!x2+Y|4CKt%fzRC5$}zAyNy}Vf4B3}abX8s z1NRAZc;fTZhC~^?(9a+IM0D-LF|7;p68C76_M9LkqGT-5y5cMPfIdCE!SWA8M=x%$ zdhOE#CakfeBkTI4McNn1O`d0r^CNyBYrvEp I!VY%-0DhQ~z5oCK literal 0 HcmV?d00001 diff --git a/4thweek/bin/jsp/jspReader.class b/4thweek/bin/jsp/jspReader.class new file mode 100755 index 0000000000000000000000000000000000000000..52b18fc0c016fcf0b78199936db9dbef2c6ee7c6 GIT binary patch literal 5516 zcmb7I3v?V+8UAKwv$MOIytcfSmfA-Wl9VKES`jvFfu^M`P0~U_N=l)fB$ITL&F(Tg zX<7?b5fBluAX-5X1Z;~S(AOrV6s!VOLz=A?}@|;bejB6T*v)h=x!y z)}9}W8!AdAoIKhl3kG6wnlpfM34wvMVb*lT%n&M2rJ{0#gaWNI>WESYL1mkF8t~nak z>1K;@#ek9MH0mo?1+Y>=bZ*%c(@3Y1iL_CZ&ZbN2#*|Sp%`!Gvwd<_@c>R=4o+Wr* zPe&xZ`&@Mrm7Qm&9%X0n+87|XsIo8nIrjd&4oecAZ@fK`)X;#=`VMF3v56X^JpupN6=|#=OpWGR^c( zAf+Nn6Ccf%MH@Pelod-RG+ZH2i)_LzmfqRdYEp+FQzos!!T@C;W0nv{LOO4Skby!P zdVhTggV?BIgGYQMSi>g~qG4RAD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J~yw7kA>KDA*_n?G4SFLgFoaifD19 zcpsjZurgA(4~HcPOHkMhe!i3C<)Hk&{2>y`IX?IlP91islR_*&;BO|cf@`r5TX+XQ zh-G*YO*qWU^lP{fZ{s3-gcfNcTBTB4ELEdTI+K^TrQ<}sl5tor5kt= z-OBss4&F5%6DjF!q~!@1luNNuJ{_CnMYu{{g3WRd-zKh>2XT#j zE3T98!}anu+#o-N8|6c|S$>=E_i&5+KDNsL!R>6WcPgd0ONsJ*4(?VK;~u36_bQj* zenrPNr5ihxYw>_`KORyZz{AR3JgPj8UCKMyt-Qu z4}_@ACcGo?sMBivjw_9tt;Fx~E()mMGW-F5L?N}Di9g}bD58!<_zV7uVrnQTzsGq) zG?XWhe}qoaoDO0)mZ?sA0j0Hj4F1MW!%5=^Z~SB65$jmYHRE8~Bu7yVBX1OUyOH^i zpb??b5Q;219X`Nb6)%esOZ V@7q`(;9q=;$?OH*K|k~d{|h)sh{FH? literal 0 HcmV?d00001 diff --git a/4thweek/part/part_1.txt b/4thweek/part/part_1.txt new file mode 100755 index 0000000..8c73e95 --- /dev/null +++ b/4thweek/part/part_1.txt @@ -0,0 +1,11 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.text.*; +import java.util.*; + +public class \ No newline at end of file diff --git a/4thweek/part/part_2.txt b/4thweek/part/part_2.txt new file mode 100755 index 0000000..28956d9 --- /dev/null +++ b/4thweek/part/part_2.txt @@ -0,0 +1,5 @@ +implements Servlet { + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("HTTP/1.1 200 OK\r\n"); + out.println(" \ No newline at end of file diff --git a/4thweek/part/part_3.txt b/4thweek/part/part_3.txt new file mode 100755 index 0000000..45b84d9 --- /dev/null +++ b/4thweek/part/part_3.txt @@ -0,0 +1,25 @@ + "); +} + + + public void destroy() { + + } + + + public ServletConfig getServletConfig() { + + return null; + } + + + public String getServletInfo() { + + return null; + } + + + public void init(ServletConfig arg0) throws ServletException { + + } +} \ No newline at end of file diff --git a/4thweek/part/part_4.txt b/4thweek/part/part_4.txt new file mode 100755 index 0000000..e85bd9f --- /dev/null +++ b/4thweek/part/part_4.txt @@ -0,0 +1,7 @@ +"); +out.println(" +out.println( +// +" +File.separator +File.separator +" +" +\" diff --git a/4thweek/src/jsp/Constants.java b/4thweek/src/jsp/Constants.java new file mode 100755 index 0000000..9a1c72b --- /dev/null +++ b/4thweek/src/jsp/Constants.java @@ -0,0 +1,11 @@ +package jsp; + +import java.io.File; + +public class Constants { + public static final String WEB_ROOT = System.getProperty("user.dir") + + File.separator; + public static final String WEB_SERVLET_ROOT = System.getProperty("user.dir") + + File.separator + "target" + File.separator + "classes"; + +} diff --git a/4thweek/src/jsp/HttpServer.java b/4thweek/src/jsp/HttpServer.java new file mode 100755 index 0000000..7d0639c --- /dev/null +++ b/4thweek/src/jsp/HttpServer.java @@ -0,0 +1,254 @@ +package jsp; + +import java.net.Socket; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import jsp.Request; +import jsp.Response; +import jsp.jspReader; + +import java.net.ServerSocket; +import java.net.InetAddress; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.File; +import java.io.IOException; + +public class HttpServer { + + // رշ + private static final String SHUTDOWN_COMMAND = "/SHUTDOWN"; + + public static void main(String[] args) { + HttpServer server = new HttpServer(); + // ȴ + server.await(); + } + + public void await() { + ServerSocket serverSocket = null; + int port = 8080; + try { + // ׽ֶ + serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1")); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + + // ѭȴ + while (true) { + Socket socket = null; + InputStream input = null; + OutputStream output = null; + try { + // ȴӣӳɹ󣬷һSocket + socket = serverSocket.accept(); + input = socket.getInputStream(); + output = socket.getOutputStream(); + + // Request󲢽 + Request request = new Request(input); + request.parse(); + + // Response + Response response = new Response(output); + response.setRequest(request); + + // ȡurl + String url = request.getUri(); + + // xml + /* + * Boolean canRead = findurl(url); + * + * if(canRead) { + * //xmlõ + * String servletName = getServeletName(url); + * ServletProcessor processor = new ServletProcessor(); + * processor.process(request,response,servletName); + * } + * else { + * StaticResourceProcessor + * processor = new StaticResourceProcessor(); + * processor.process(request, response); } + */ + String filename = System.getProperty("user.dir")+ File.separator +"jsp" + File.separator + url; + if(new File(filename).exists()) + { + // תjsp + jspReader jsp = new jspReader(url.split("/")[1]); + ServletProcessor processor = new ServletProcessor(); + processor.process(request,response,jsp.getServletName()); + } + else + { + System.out.println("Ҳļ"); + } + + + // ر socket + socket.close(); + + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + } + + public Boolean findurl(String url) { + Element element = null; + // ʹþ· + File f = new File("web.xml"); + + DocumentBuilder db = null; + DocumentBuilderFactory dbf = null; + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + Document dt = db.parse(f); + + // õһelmentԪ + element = dt.getDocumentElement(); + + // øԪµӽڵ + NodeList childNodes = element.getChildNodes(); + + NodeList theNodeList = null; + + // Щӽڵ + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһservelet-mappinguri + if ("servlet-mapping".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("url-pattern".equals(detail.getNodeName())) { + // ƥurl + if (url.equals(detail.getTextContent()))// ƥ䵽true + return true; + } + + } + } + } + } + + catch (Exception e) { + System.out.println(e.toString()); + } + + return false; + } + + public String getServeletName(String url) { + String ServeletName = null; + + Element element = null; + // ʹþ· + File f = new File("web.xml"); + + DocumentBuilder db = null; + DocumentBuilderFactory dbf = null; + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + Document dt = db.parse(f); + + // õһelmentԪ + element = dt.getDocumentElement(); + + // øԪµӽڵ + NodeList childNodes = element.getChildNodes(); + + NodeList theNodeList = null; + + // Щӽڵ + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһservelet-mappinguri + if ("servlet-mapping".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("url-pattern".equals(detail.getNodeName())) { + // ƥurl + if (url.equals(detail.getTextContent()))// ƥ䵽ýڵȡ + theNodeList = nodeDetail; + } + + } + } + } + + String Sname = null; + // ȡ + for (int j = 0; j < theNodeList.getLength(); j++) { + Node detail = theNodeList.item(j); + + if ("servlet-name".equals(detail.getNodeName())) // ƥname + { + Sname = detail.getTextContent(); + } + + } + + NodeList theNodeList1 = null; + + // ٴαƥӦservelet-class + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһserveleturi + if ("servlet".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("servlet-name".equals(detail.getNodeName())) // ƥurlӦ + if (Sname.equals(detail.getTextContent()))// ƥ䵽ýڵȡ + theNodeList1 = nodeDetail; + } + } + } + // ȡserveletname + for (int j = 0; j < theNodeList1.getLength(); j++) { + Node detail = theNodeList1.item(j); + + if ("servlet-class".equals(detail.getNodeName())) // ƥ + { + ServeletName = detail.getTextContent(); + } + + } + } + + catch (Exception e) { + e.printStackTrace(); + } + + return ServeletName; + } +} diff --git a/4thweek/src/jsp/Request.java b/4thweek/src/jsp/Request.java new file mode 100755 index 0000000..6185a1d --- /dev/null +++ b/4thweek/src/jsp/Request.java @@ -0,0 +1,188 @@ +package jsp; + +import java.io.InputStream; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; + +public class Request implements ServletRequest { + + private InputStream input; + private String uri; + + public Request(InputStream input) { + this.input = input; + } + + public String getUri() { + return uri; + } + /** + * + * requestStringʽ£ + * GET /index.html HTTP/1.1 + * Host: localhost:8080 + * Connection: keep-alive + * Cache-Control: max-age=0 + * ... + * úĿľΪ˻ȡ/index.htmlַ + */ + private String parseUri(String requestString) { + int index1, index2; + index1 = requestString.indexOf(' '); + if (index1 != -1) { + index2 = requestString.indexOf(' ', index1 + 1); + if (index2 > index1) + return requestString.substring(index1 + 1, index2); + } + return null; + } + //InputStreamжȡrequestϢrequestлȡuriֵ + public void parse() { + // Read a set of characters from the socket + StringBuffer request = new StringBuffer(2048); + int i; + byte[] buffer = new byte[2048]; + try { + i = input.read(buffer); + } catch (IOException e) { + e.printStackTrace(); + i = -1; + } + for (int j = 0; j < i; j++) { + request.append((char) buffer[j]); + } + System.out.print(request.toString()); + uri = parseUri(request.toString()); + } + + /* implementation of the ServletRequest */ + public Object getAttribute(String attribute) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public String getRealPath(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public boolean isSecure() { + return false; + } + + public String getCharacterEncoding() { + return null; + } + + public int getContentLength() { + return 0; + } + + public String getContentType() { + return null; + } + + public ServletInputStream getInputStream() throws IOException { + return null; + } + + public Locale getLocale() { + return null; + } + + public Enumeration getLocales() { + return null; + } + + public String getParameter(String name) { + return null; + } + + public Map getParameterMap() { + return null; + } + + public Enumeration getParameterNames() { + return null; + } + + public String[] getParameterValues(String parameter) { + return null; + } + + public String getProtocol() { + return null; + } + + public BufferedReader getReader() throws IOException { + return null; + } + + public String getRemoteAddr() { + return null; + } + + public String getRemoteHost() { + return null; + } + + public String getScheme() { + return null; + } + + public String getServerName() { + return null; + } + + public int getServerPort() { + return 0; + } + + public void removeAttribute(String attribute) { + } + + public void setAttribute(String key, Object value) { + } + + public void setCharacterEncoding(String encoding) + throws UnsupportedEncodingException { + } + +@Override +public String getLocalAddr() { + // TODO Auto-generated method stub + return null; +} + +@Override +public String getLocalName() { + // TODO Auto-generated method stub + return null; +} + +@Override +public int getLocalPort() { + // TODO Auto-generated method stub + return 0; +} + +@Override +public int getRemotePort() { + // TODO Auto-generated method stub + return 0; +} + +} diff --git a/4thweek/src/jsp/Response.java b/4thweek/src/jsp/Response.java new file mode 100755 index 0000000..eb6bd12 --- /dev/null +++ b/4thweek/src/jsp/Response.java @@ -0,0 +1,115 @@ +package jsp; + +import java.io.OutputStream; +import java.io.IOException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.File; +import java.io.PrintWriter; +import java.util.Locale; +import javax.servlet.ServletResponse; +import javax.servlet.ServletOutputStream; + +public class Response implements ServletResponse { + + private static final int BUFFER_SIZE = 1024; + Request request; + OutputStream output; + PrintWriter writer; + + public Response(OutputStream output) { + this.output = output; + } + + public void setRequest(Request request) { + this.request = request; + } + + //webļд뵽OutputStreamֽ +//webļд뵽OutputStreamֽ +public void sendStaticResource() throws IOException { +byte[] bytes = new byte[BUFFER_SIZE]; +FileInputStream fis = null; +try { +/* request.getUri has been replaced by request.getRequestURI */ +File file = new File(Constants.WEB_ROOT, request.getUri()); +fis = new FileInputStream(file); +/* +* HTTP Response = Status-Line(( general-header | response-header | +* entity-header ) CRLF) CRLF [ message-body ] Status-Line = +* HTTP-Version SP Status-Code SP Reason-Phrase CRLF +*/ +int ch = fis.read(bytes, 0, BUFFER_SIZE); +while (ch != -1) { +output.write(bytes, 0, ch); +ch = fis.read(bytes, 0, BUFFER_SIZE); +} +} catch (FileNotFoundException e) { +String errorMessage = "HTTP/1.1 404 File Not Found\r\n" + + "Content-Type: text/html\r\n" + "Content-Length: 23\r\n" + + "\r\n" + "

File Not Found

"; +output.write(errorMessage.getBytes()); +} finally { +if (fis != null) +fis.close(); +} +} + + + /** implementation of ServletResponse */ + public void flushBuffer() throws IOException { + } + + public int getBufferSize() { + return 0; + } + + public String getCharacterEncoding() { + return null; + } + + public Locale getLocale() { + return null; + } + + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + public PrintWriter getWriter() throws IOException { + // autoflush is true, println() will flush, + // but print() will not. + writer = new PrintWriter(output, true); + return writer; + } + + public boolean isCommitted() { + return false; + } + + public void reset() { + } + + public void resetBuffer() { + } + + public void setBufferSize(int size) { + } + + public void setContentLength(int length) { + } + + public void setContentType(String type) { + } + + public void setLocale(Locale locale) { + } + +public String getContentType() { + return null; +} + +public void setCharacterEncoding(String arg0) { +} + +} diff --git a/4thweek/src/jsp/ServletProcessor.java b/4thweek/src/jsp/ServletProcessor.java new file mode 100755 index 0000000..7dc2ae2 --- /dev/null +++ b/4thweek/src/jsp/ServletProcessor.java @@ -0,0 +1,56 @@ +package jsp; + +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLStreamHandler; +import java.io.File; +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import jsp.Request; +import jsp.Response; + +public class ServletProcessor { + + public void process(Request request, Response response,String servletName) { + + //ڴָJARļĿ¼ + URLClassLoader loader = null; + try { + URLStreamHandler streamHandler = null; + // + System.out.println(System.getProperty("user.dir")+ File.separator+ "work" + File.separator); + loader = new URLClassLoader(new URL[]{new URL(null, "file:" + + System.getProperty("user.dir")+ File.separator+ "work" + File.separator, + streamHandler)}); + } catch (IOException e) { + System.out.println(e.toString()); + } + + Class myClass = null; + try { + //ضӦservlet + myClass = loader.loadClass(servletName); + } catch (ClassNotFoundException e) { + System.out.println(e.toString()); + } + + Servlet servlet = null; + + try { + //servletʵ + servlet = (Servlet) myClass.newInstance(); + //ִervletservice + servlet.service((ServletRequest) request,(ServletResponse) response); + } catch (Exception e) { + System.out.println(e.toString()); + } catch (Throwable e) { + System.out.println(e.toString()); + } + + } + +} diff --git a/4thweek/src/jsp/StaticResourceProcessor.java b/4thweek/src/jsp/StaticResourceProcessor.java new file mode 100755 index 0000000..894e6ef --- /dev/null +++ b/4thweek/src/jsp/StaticResourceProcessor.java @@ -0,0 +1,15 @@ +package jsp; + +import java.io.IOException; + +public class StaticResourceProcessor { + + public void process(Request request, Response response) { + try { + response.sendStaticResource(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + \ No newline at end of file diff --git a/4thweek/src/jsp/aa.java b/4thweek/src/jsp/aa.java new file mode 100755 index 0000000..e69de29 diff --git a/4thweek/src/jsp/jspReader.java b/4thweek/src/jsp/jspReader.java new file mode 100755 index 0000000..ca211c8 --- /dev/null +++ b/4thweek/src/jsp/jspReader.java @@ -0,0 +1,193 @@ +package jsp; + +import java.io.*; +import java.net.URLClassLoader; +import java.util.Arrays; + +import javax.tools.*; + +public class jspReader { + + private String jspName; + private String jspContent = null; + private String ServeletContent = null; + + public jspReader(String uri) { + jspName = uri; + Read(); + makeServlet(); + } + + public void init() { + + } + + public void Read() { + File f = new File(System.getProperty("user.dir") + File.separator + "jsp" + File.separator + jspName); + + BufferedReader br; + + try { + br = new BufferedReader(new FileReader(f)); + + String line = br.readLine(); + + if(line.contains("<%@")) + { + line = "<% response.setContentType(\"text/html; charset=gb2312\");%>"; + line = line.replace("\"", "&&&&"); + } + + jspContent = line; + + while ((line = br.readLine()) != null) { + + if(line.contains("<%=")) + { + line = line.replace("<%=", "$$out.println("); + line = line.replace("%>", ");&&"); + line = line.replace("\"", "&&&&"); + } + + jspContent = jspContent + " " + line; + } + + br.close(); + // System.out.println(jspContent); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(jspContent); + } + + public void makeServlet() { + // ȡ4ļ + File f1 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_1.txt"); + File f2 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_2.txt"); + File f3 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_3.txt"); + File f4 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_4.txt"); + + BufferedReader br1, br2, br3, br4; + + try { + // part4 + br4 = new BufferedReader(new FileReader(f4)); + + String line = null; + + String[] sign = new String[7]; + + sign[0] = br4.readLine(); + sign[1] = "\n" + br4.readLine() ; + sign[2] = sign[0] + br4.readLine(); + sign[3] = br4.readLine(); + sign[4] = br4.readLine(); + sign[5] = br4.readLine(); + sign[6] = br4.readLine(); + + br4.close(); + // + // 滻 + // String ServeletContent1 = jspContent.replace(sign[5], sign[6]); + String ServeletContent1 = jspContent.replace("$$out.println(", sign[2]); + ServeletContent1 = ServeletContent1.replace(");&&",");" + sign[1] ); + ServeletContent1 = ServeletContent1.replace("<%", sign[0]); + ServeletContent1 = ServeletContent1.replace("%>", sign[1]); + ServeletContent1 = ServeletContent1.replace("&&&&", sign[5]); + + + // import-class + br1 = new BufferedReader(new FileReader(f1)); + + line = null; + + ServeletContent = br1.readLine(); + + while ((line = br1.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br1.close(); + // + + ServeletContent = ServeletContent + "\n" + jspName.split(".jsp")[0] + "Servlet\n"; + // System.out.println(jspName.split(".jsp")[0]); + + // part2 + br2 = new BufferedReader(new FileReader(f2)); + + line = null; + + ServeletContent = ServeletContent + br2.readLine(); + + while ((line = br2.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br2.close(); + // + ServeletContent = ServeletContent + ServeletContent1; + // part3 + br3 = new BufferedReader(new FileReader(f3)); + + line = null; + + ServeletContent = ServeletContent + br3.readLine(); + + while ((line = br3.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br3.close(); + // + + + + // System.out.println(ServeletContent); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // java + File f = new File(System.getProperty("user.dir") + File.separator + "work" + File.separator + + jspName.split(".jsp")[0] + "Servlet.java"); + try { + if (!f.exists()) { + f.createNewFile(); + } + FileWriter fw = new FileWriter(f); + + fw.write(ServeletContent); + + fw.close(); + + String dir = System.getProperty("user.dir") + File.separator+ "work"; + String filename = jspName.split(".jsp")[0] + "Servlet.java"; + + // ϵͳ + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + + StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); + // Դļ + Iterable fileObject = fileManager.getJavaFileObjects(new File(dir,filename)); + // + JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d", "./work"), + null, fileObject); + task.call(); + + fileManager.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public String getServletName() + { + return jspName.split(".jsp")[0] + "Servlet"; + } +} From e7fa54dca12fb94c72ea53fe0f970c2340603b28 Mon Sep 17 00:00:00 2001 From: Gust <573848754@qq.com> Date: Sun, 23 Oct 2016 11:34:08 +0800 Subject: [PATCH 14/14] zuoye --- 14301056/.DS_Store | Bin 6148 -> 6148 bytes 14301056/app.py | 14 - 14301056/bin/.DS_Store | Bin 0 -> 6148 bytes 14301056/bin/jsp/Constants.class | Bin 0 -> 922 bytes 14301056/bin/jsp/HttpServer.class | Bin 0 -> 5947 bytes 14301056/bin/jsp/Request.class | Bin 0 -> 4509 bytes 14301056/bin/jsp/Response.class | Bin 0 -> 3365 bytes 14301056/bin/jsp/ServletProcessor.class | Bin 0 -> 2429 bytes .../bin/jsp/StaticResourceProcessor.class | Bin 0 -> 677 bytes 14301056/bin/jsp/jspReader.class | Bin 0 -> 5516 bytes 14301056/middleware.py | 14 - 14301056/part/part_1.txt | 11 + 14301056/part/part_2.txt | 5 + 14301056/part/part_3.txt | 25 ++ 14301056/part/part_4.txt | 7 + 14301056/server.py | 115 -------- 14301056/src/jsp/Constants.java | 11 + 14301056/src/jsp/HttpServer.java | 254 ++++++++++++++++++ 14301056/src/jsp/Request.java | 188 +++++++++++++ 14301056/src/jsp/Response.java | 115 ++++++++ 14301056/src/jsp/ServletProcessor.java | 56 ++++ 14301056/src/jsp/StaticResourceProcessor.java | 15 ++ 14301056/src/jsp/aa.java | 0 14301056/src/jsp/jspReader.java | 193 +++++++++++++ 24 files changed, 880 insertions(+), 143 deletions(-) delete mode 100644 14301056/app.py create mode 100644 14301056/bin/.DS_Store create mode 100755 14301056/bin/jsp/Constants.class create mode 100755 14301056/bin/jsp/HttpServer.class create mode 100755 14301056/bin/jsp/Request.class create mode 100755 14301056/bin/jsp/Response.class create mode 100755 14301056/bin/jsp/ServletProcessor.class create mode 100755 14301056/bin/jsp/StaticResourceProcessor.class create mode 100755 14301056/bin/jsp/jspReader.class delete mode 100644 14301056/middleware.py create mode 100755 14301056/part/part_1.txt create mode 100755 14301056/part/part_2.txt create mode 100755 14301056/part/part_3.txt create mode 100755 14301056/part/part_4.txt delete mode 100755 14301056/server.py create mode 100755 14301056/src/jsp/Constants.java create mode 100755 14301056/src/jsp/HttpServer.java create mode 100755 14301056/src/jsp/Request.java create mode 100755 14301056/src/jsp/Response.java create mode 100755 14301056/src/jsp/ServletProcessor.java create mode 100755 14301056/src/jsp/StaticResourceProcessor.java create mode 100755 14301056/src/jsp/aa.java create mode 100755 14301056/src/jsp/jspReader.java diff --git a/14301056/.DS_Store b/14301056/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..02365afb0db51e2a5806f8840ba72e60f9885fae 100644 GIT binary patch delta 153 zcmZoMXfc=|&e%RNQEZ}~qA)W90|O%ig8)NOUQT{qI*2zhQPUM9%*>F)kjao&7L1Sr zin1^iFeEY*F_fT*GcyzeMU#<5Hzu01Pc{%?+04zs!@=0TG4VU|WPTAvK_;Lv3P79y M#9*-5QRFZ)0P&I^yZ`_I delta 68 zcmZoMXfc=|&Zs)EP;8=}A_oHyFfuR*Y`kd3KJh`-W_At%4o20D7r!%4<`+>E1WGX^ QfYbm1h~2Q+QRFZ)066Lo1poj5 diff --git a/14301056/app.py b/14301056/app.py deleted file mode 100644 index 905fb27..0000000 --- a/14301056/app.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding: utf-8 -from __future__ import unicode_literals -from wsgiref import simple_server - - -def app(environ, start_response): - status = '200 OK' - response_headers = [('Content-Type', 'text/html')] - start_response(status, response_headers) - str = environ['PATH_INFO'][1:] - print str - - # return '

Hello, %s!

' % (environ['PATH_INFO'][1:] or 'web') - # return ['Hello world from a RAPOWSGI application!\n'] \ No newline at end of file diff --git a/14301056/bin/.DS_Store b/14301056/bin/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3623d60ee3027646409e01f7c03cb53389473b72 GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHMLVF(!GgoLD?qvz?T@g{Xx!V^euq*<}M zU$L_SVEfPW6EFeT&|R_fFf(Jm!UZ3A`#QbfuCKQjR=f&4M9hqp3A6p$mWY4|h=2%) zfCwyzK%U~*JTB;&^e7@A0?Q!a--kwb?WH3%J{=4(0#Mg1hjAUV1hsjA+Dk_&D>SR= z!K&3_4DoujQ(IlvOGj$9!)o}jy0iHdL$hp$H6}FcAqpZO0y6@u%qKtpkM!T>|5=Mt z5fFiYM!?pG(_zn-sv{dTs=gj{YFy56_Y=UxkK!#ojQhqikV@VZImko!!6>weWRlVU}UBCys>U z3BT*qT0Pm;4EFoV&c}mVt-+9~o|o%dxqi1qS4_QLIcQcZjZvRnZhNlp>emdhT)xRL zyBl<*1@Dj z9+|3x;af2*<)%!K0HJftA#TGVMlBS1YvU2Q(e^|b%FwiIb67@ay6XD!-Qch#RYSBq zX|^J03$H1ZYtB(Ji5Q+6R}%F0`m-CFdt=*1i<7Je1J#zs1BQkFdssB)V1p=Qw5v1p zE+mcqRt$fXv0=kVO48{|)CIi#iPVS8{29_`$ev>L8`e*7`vke~xIeX&DN=pdm3jED z_3_t;;0b-#hz>-UrkJI;N~8s%eM51N;?t-TB!i|LiE$`0%Fh)}@$4KbK1@be_~`!y MUQ#2&s|cp_7xsnES^xk5 literal 0 HcmV?d00001 diff --git a/14301056/bin/jsp/HttpServer.class b/14301056/bin/jsp/HttpServer.class new file mode 100755 index 0000000000000000000000000000000000000000..2bb99773c88a4aedfe42aeed3350e02a9c381907 GIT binary patch literal 5947 zcma)A33yc175;BBnK#SJLSQ0KaRCIAunZu^I#G~SL$g@IVsM>IUSMD{Gt9gYC~aLD z7p#c2?$y?%n%Y`L(Me(~)E%{2wN|UO+A5;m)Y@vXwx<8R?@cm;srV7z%)R&AbIv{I zKmWOJp8D*8od9MFLqmZ;$=Y->c(P?Bo6Xb)Go`^LP_{O_Asmc_9W>D z({!pn-+9`1b%djFfr`r0KJQ)C3Lki2`8Y_&SZS{)+!c=Uc&>12H5HB?VHcfFJE1vL zAfV11H?5!@ujWK#ooRV+IL|qA*0IxP@ZU@y#$%#}2?Aq=#Ot_cURztrOs91miAj`S zZCdj;HHJHQ%IeAy+_k5qt(?uZK8(XrGF+7chg80jsQ&CdT0y z9W^+XK?+BtYFewT8g|JJ4}CrkwHiW9@K8YPB^}4(1SW;CsEa2%=}O8BcQ8R&Ez<4b z1*K`OjuSDDy11#S)5_U3HfLAv3T-bC@JqBTHP?5VY0HQCSR|vkSYWIZ{QXSH^UcS} zI_eZslHpX^)bLdS-PV&%66%cD5;RCfjRMB7qCD$T(-NGb<7-$d;7gm9;|0UaEyG^b z+BTQzSPqtln+IH;iV{ZIbE%qiicQ0*jFXCI&h-4wXspdld9X^r(@Eq`Z;Pg6T2I$; z2F_#@sPvRnB59_qO#+kuKk#ytGVEugRYN!*7pmxWM9?OnZIA`u)V`len?GtDNaU+r ziFO&d)vT(KyjbBy6zepsl@XVO#QZFd#!MYCxLH1FlPL*X37&2x2*qvW>`i4TLK~|qjs*2^Kd?yCY_AQ!Z~Urzeb=PA2y?1!v&H)+9FDYh~-$y7q_5|}~bIcReRHjryS7aXF|OW5wjL)I(f_dPD{-Li8}-`2M;-u~|0x9z?9qCEqd_a8jZhpTXnhO2XU zC}*dRYb5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70%y^`?!8Ty;+K)L58VNgU~RJkkL@>8KhyKGo#@+4H*r68s=+QqTy`* z0oouHxc8Tl+i&EF9st2B;a0GiCy=M!EgEF5%O7N}9enj+XQ;?1%HYwE%a9P;Epyn9 zX9OCi_T$$AAx(rlg*DzDtTVKLw;!(*Aml55!|?Uvj{+I&y$+3X@Mp^U3v2Wq9Budm zx-D2-{uiToSg>M>9R1DN<{?l%*xs#+fNuEv@sYsIgHLpOMZjxl&Tv}~%0h0!OrrV| zBCSwvVV25qC2ilxEA0;TX(Owh*#qB73J~YXlSJEkN~W0s3y1MtVlp-oQJaaWZ}NV7 zE^%}|5p@A^a}n{f1#55#r7z{|WxQ%{qxLOC!nw3@6|G!@K3k?<1-8rKjp|U!Q?*rvQ-p_LZ*=32$v`#evacijho** zd>QXz9&aH|mhc7ABfP{qxq8G3;5k%A?}RmremV2T`Naitl0$lF~k0>uVls9?3b+b04(!{ZDu7a?C^jlT!g zhBrVPQl&mxlt}rkaa|6mGUV&_i-6xC^p&dTgah*q`kjUOXi=7n^Cmfvj+YeHl=fh@ zQ4%P%t&~YCWy4k~44)hhyIvCVcbAGlsXUOf_qbgkS=YC!606E7vC*PD*S6m&v4;G@ zdcFrfnS%^&n7W-w42V0#okNuTI4KvT!UB?@i!drB@s*Q-0wleINqFN)dDSGjStPX( zN$dm?*8&n+BWdOg!n_?jS$4b7g@rp%0*px8$nal0ZQ=1?3&lop7w{{!oW?QH-6 literal 0 HcmV?d00001 diff --git a/14301056/bin/jsp/Request.class b/14301056/bin/jsp/Request.class new file mode 100755 index 0000000000000000000000000000000000000000..a7b708c7fc52fb3d78e5149baf809934d6b39bff GIT binary patch literal 4509 zcmb7GYjYGu6g|D!u*qhCLIYgkOU!uL?Ve<2x3H?>^8}S&CD`88^IU8 z-|y!KtF*MN;)_=KB9xEv2l#9J0hD;UXEHlsCzYirc4oToIeqTEr@Qmde}DW9U?;vv zAtBH*Q!Zu4%2%_F;{-oa~Sq$a$_bXZHy-R9s8oCVy6Q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^LV z$8d@>w-WU@CRnE)*5V1qC3PkEyhc&U6hw-!6i%y`zH97zFvic*z*RH~)z>HSlwU7u z<0VEV3Eiit3kD-*N`yU0;A!0x0TYu%<`otNZPdHSr94y1^-#o73tR#+bkx!+jxM3% zOrT;4)5~TuvJ8iXnSdkApy3CdS9MS1Vly}!Zm1AhQ^%9B$RcK!U2`H9Y1gslQ?W<~ zCHCqZGfQ&qzGZrrkL7StzFv1t##6CK?*{yGHkP4MhhH3x^pC&=rzwZd1%7!3=R?Oj65i+r^XZ*BjY{YnFUtMYHd;I_?O i&`Ysp`M3_`kFm&4>S)EUvB*#BK>i+!{7kp*^Zx-5yzV&w literal 0 HcmV?d00001 diff --git a/14301056/bin/jsp/Response.class b/14301056/bin/jsp/Response.class new file mode 100755 index 0000000000000000000000000000000000000000..86fc34718772925f493cf6e739cea87b511bc96f GIT binary patch literal 3365 zcma)8TUQfT6#h;!WFQ6w1r=HgR;k=1pokXG+8{_;ZW0IuTI~>qWH2N+nc$_`i@pDg zuDH|DyCeXL1>Ci$3JcnRE93&feet_L=u4jb^1LGRxez+gDNs2#9Jw<+IXNS9QGTktWY)?g z2ZHEAw~jE2=m|E29$X-&Nz<9NErGh$w!K_i&?|YoByg@kx)*x4M_XLSWq}jk=%X1H z-Ys(weRx{}_6yXOt0;3EXp76;!4R&3HP)z#WeTcwF%pfoMT5AGh>mv|Xc5|5`VfY2 zL!d%QsN@x|#E3v*bY^BM+|$+5+}qvTERSlQ$U4m<*?eZXI!G=ZGvl0}dAM%&H#_D7 zC!BKD(&ddYGm~^u{mmCHRtKwtgQ=ct+aU(STnb_o@9AJ$c-qV5KZN%&#u}06$V11Z zrnJ_!#fVI3LWVubu$iQr{jCtDrD!V>>8$KmR#bInQ3woN#a+@0O_y9$-(rMfUy-71 zaO+YKkB5HhS6d+gO4lBJaov|lv9Gz)w9R?ffiw-7ww<-d&0Nk%(xI9fPuv|h)>Y@| zpaPbP!d7CLN!i)^ZmS(yN#}E^NPcBSHhQ(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YX1 zdW_V^$$DJEWdmR03fa*zOM5vPR?(#W`i-~pHLapYud%(V3;encUNE87)HJ81#hCQM zb=O%A2aL{~ zNZ$9xNBc^pKHfJsW;DEig!-KY-z?rZZ&re@fW&RWsy_e`@e<$arx{#?TnnTNPSq_c zJ))Rjq2ViaNOv7}gEO5UG@y+;eulV8p0fNE{7vp(MaSbnoaU;{Np)-l08a~Y>wJ60rGN~FS z15rwAP5*&Qxl|@~;NUO#q8$&>my=pc*6$(dWUg%H0xuYu-c4Wm?|i%@xR( z1SKgUBvvH8k=P|UhItw@Ua~z>4HAih7EV#P6|z|)y!+pmfZMgFvzNl~4 literal 0 HcmV?d00001 diff --git a/14301056/bin/jsp/StaticResourceProcessor.class b/14301056/bin/jsp/StaticResourceProcessor.class new file mode 100755 index 0000000000000000000000000000000000000000..c72073d051fde3f0aea058062e0a09f5d4ccbadd GIT binary patch literal 677 zcmaJVEb$+C=7I?a zetMA>JRAcfJU6&J^>(92#bzPS> zL?BomsVkL@Rq-V|9*%V02o_$O!ZdFLb9?&(LGZRb*D>a>m|z|Yf~CGG^wH#EsO^~= zjC~F*UFN5Z*sRf(;|48Tw!fL8Vu(jt?PxR$P*G;blbyXI%?(Gj^Jitnb zt{`!Y9LGlzJanSEwJy$Q2aU0Y#~~gGR{W5r%sw8!`=0BnF=dh9i65r2rf680e><}( z=P;q23J|0-dIXVedkXH)suKt+SNs3y!x2+Y|4CKt%fzRC5$}zAyNy}Vf4B3}abX8s z1NRAZc;fTZhC~^?(9a+IM0D-LF|7;p68C76_M9LkqGT-5y5cMPfIdCE!SWA8M=x%$ zdhOE#CakfeBkTI4McNn1O`d0r^CNyBYrvEp I!VY%-0DhQ~z5oCK literal 0 HcmV?d00001 diff --git a/14301056/bin/jsp/jspReader.class b/14301056/bin/jsp/jspReader.class new file mode 100755 index 0000000000000000000000000000000000000000..52b18fc0c016fcf0b78199936db9dbef2c6ee7c6 GIT binary patch literal 5516 zcmb7I3v?V+8UAKwv$MOIytcfSmfA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Y{#PN@LC%K$F^CHlNYV@NP>oF6XIl*7g%i1>XKf*D5H_m2ns>goJ z!_$~=TXPO=MvJ-Dtix^Cge%E;0q3Tx@F}`$F$b~DbdtieK71OV;p%FhnFjwySgm5J ziUt)m>h#l&(D||oiF@La@R1I$RD3d+{BQ6MRs#6)$M?=>v)&0`o9mnLyqSalxh#Iu zanb*L7Qgwp@V}77kNUh|iTIpoi3X%-uvk5SnrJ8zQX&C5wj~lG9z*aZ2A{p-5a52E z*e70{6BQ$Ye($vEEdt)6*n^RNuLzQG2Z_}&;-dMH{BXC;?u&w5$j4m~+8*o{!Or{W za^TLXRgqA@fp}WEDG<%0QdN;W>cW)Yj%ihHFqgQ&d=ptjf({>I*qH6n;GrY0h-L3s z=pyIBU&`RiLYT9{w`UJ~yw7kA>KDA*_n?G4SFLgFoaifD19 zcpsjZurgA(4~HcPOHkMhe!i3C<)Hk&{2>y`IX?IlP91islR_*&;BO|cf@`r5TX+XQ zh-G*YO*qWU^lP{fZ{s3-gcfNcTBTB4ELEdTI+K^TrQ<}sl5tor5kt= z-OBss4&F5%6DjF!q~!@1luNNuJ{_CnMYu{{g3WRd-zKh>2XT#j zE3T98!}anu+#o-N8|6c|S$>=E_i&5+KDNsL!R>6WcPgd0ONsJ*4(?VK;~u36_bQj* zenrPNr5ihxYw>_`KORyZz{AR3JgPj8UCKMyt-Qu z4}_@ACcGo?sMBivjw_9tt;Fx~E()mMGW-F5L?N}Di9g}bD58!<_zV7uVrnQTzsGq) zG?XWhe}qoaoDO0)mZ?sA0j0Hj4F1MW!%5=^Z~SB65$jmYHRE8~Bu7yVBX1OUyOH^i zpb??b5Q;219X`Nb6)%esOZ V@7q`(;9q=;$?OH*K|k~d{|h)sh{FH? literal 0 HcmV?d00001 diff --git a/14301056/middleware.py b/14301056/middleware.py deleted file mode 100644 index 83e4fb7..0000000 --- a/14301056/middleware.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding: utf-8 - -from __future__ import unicode_literals - - -class TestMiddle(object): - def __init__(self, application): - self.application = application - - def __call__(self, environ, start_response): - if 'postman' in environ.get('USER_AGENT'): - start_response('403 Not Allowed', []) - return ['not allowed!'] - return self.application(environ, start_response) \ No newline at end of file diff --git a/14301056/part/part_1.txt b/14301056/part/part_1.txt new file mode 100755 index 0000000..8c73e95 --- /dev/null +++ b/14301056/part/part_1.txt @@ -0,0 +1,11 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import java.text.*; +import java.util.*; + +public class \ No newline at end of file diff --git a/14301056/part/part_2.txt b/14301056/part/part_2.txt new file mode 100755 index 0000000..28956d9 --- /dev/null +++ b/14301056/part/part_2.txt @@ -0,0 +1,5 @@ +implements Servlet { + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("HTTP/1.1 200 OK\r\n"); + out.println(" \ No newline at end of file diff --git a/14301056/part/part_3.txt b/14301056/part/part_3.txt new file mode 100755 index 0000000..45b84d9 --- /dev/null +++ b/14301056/part/part_3.txt @@ -0,0 +1,25 @@ + "); +} + + + public void destroy() { + + } + + + public ServletConfig getServletConfig() { + + return null; + } + + + public String getServletInfo() { + + return null; + } + + + public void init(ServletConfig arg0) throws ServletException { + + } +} \ No newline at end of file diff --git a/14301056/part/part_4.txt b/14301056/part/part_4.txt new file mode 100755 index 0000000..e85bd9f --- /dev/null +++ b/14301056/part/part_4.txt @@ -0,0 +1,7 @@ +"); +out.println(" +out.println( +// +" +File.separator +File.separator +" +" +\" diff --git a/14301056/server.py b/14301056/server.py deleted file mode 100755 index 6fe8669..0000000 --- a/14301056/server.py +++ /dev/null @@ -1,115 +0,0 @@ -# coding: utf-8 -from __future__ import unicode_literals - -import socket -import StringIO -import sys -import datetime - -from middleware import TestMiddle -from wsgiref import simple_server - - -class WSGIServer(object): - socket_family = socket.AF_INET - socket_type = socket.SOCK_STREAM - request_queue_size = 10 - - def __init__(self, address): - self.socket = socket.socket(self.socket_family, self.socket_type) - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.socket.bind(address) - self.socket.listen(self.request_queue_size) - host, port = self.socket.getsockname()[:2] - self.host = host - self.port = port - - def set_application(self, application): - self.application = application - - def serve_forever(self): - while 1: - self.connection, client_address = self.socket.accept() - self.handle_request() - - def handle_request(self): - self.request_data = self.connection.recv(1024) - self.request_lines = self.request_data.splitlines() - try: - self.get_url_parameter() - env = self.get_environ() - app_data = self.application(env, self.start_response) - self.finish_response(app_data) - print '[{0}] "{1}" {2}'.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), - self.request_lines[0], self.status) - except Exception, e: - pass - - def get_url_parameter(self): - self.request_dict = {'Path': self.request_lines[0]} - for itm in self.request_lines[1:]: - if ':' in itm: - self.request_dict[itm.split(':')[0]] = itm.split(':')[1] - self.request_method, self.path, self.request_version = self.request_dict.get('Path').split() - - def get_environ(self): - env = { - 'wsgi.version': (1, 0), - 'wsgi.url_scheme': 'http', - 'wsgi.input': StringIO.StringIO(self.request_data), - 'wsgi.errors': sys.stderr, - 'wsgi.multithread': False, - 'wsgi.multiprocess': False, - 'wsgi.run_once': False, - 'REQUEST_METHOD': self.request_method, - 'PATH_INFO': self.path, - 'SERVER_NAME': self.host, - 'SERVER_PORT': self.port, - 'USER_AGENT': self.request_dict.get('User-Agent') - } - return env - - def start_response(self, status, response_headers): - headers = [ - ('Date', datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')), - ('Server', 'RAPOWSGI0.1'), - ] - self.headers = response_headers + headers - self.status = status - - def finish_response(self, app_data): - try: - response = 'HTTP/1.1 {status}\r\n'.format(status=self.status) - for header in self.headers: - response += '{0}: {1}\r\n'.format(*header) - response += '\r\n' - for data in app_data: - response += data - self.connection.sendall(response) - finally: - self.connection.close() - - -if __name__ == '__main__': - port = 8888 - if len(sys.argv) < 2: - sys.exit('请提供可用的wsgi应用程序, 格式为: 模块名.应用名') - elif len(sys.argv) > 2: - port = sys.argv[2] - - - def generate_server(address, application): - server = WSGIServer(address) - server.set_application(TestMiddle(application)) - return server - - - app_path = sys.argv[1] - module, application = app_path.split('.') - module = __import__(module) - application = getattr(module, application) - httpd = generate_server(('', int(port)), application) - print 'RAPOWSGI Server Serving HTTP service on port {0}'.format(port) - print '{0}'.format(datetime.datetime.now(). - strftime('%a, %d %b %Y %H:%M:%S GMT')) - httpd.serve_forever() diff --git a/14301056/src/jsp/Constants.java b/14301056/src/jsp/Constants.java new file mode 100755 index 0000000..9a1c72b --- /dev/null +++ b/14301056/src/jsp/Constants.java @@ -0,0 +1,11 @@ +package jsp; + +import java.io.File; + +public class Constants { + public static final String WEB_ROOT = System.getProperty("user.dir") + + File.separator; + public static final String WEB_SERVLET_ROOT = System.getProperty("user.dir") + + File.separator + "target" + File.separator + "classes"; + +} diff --git a/14301056/src/jsp/HttpServer.java b/14301056/src/jsp/HttpServer.java new file mode 100755 index 0000000..7d0639c --- /dev/null +++ b/14301056/src/jsp/HttpServer.java @@ -0,0 +1,254 @@ +package jsp; + +import java.net.Socket; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import jsp.Request; +import jsp.Response; +import jsp.jspReader; + +import java.net.ServerSocket; +import java.net.InetAddress; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.File; +import java.io.IOException; + +public class HttpServer { + + // رշ + private static final String SHUTDOWN_COMMAND = "/SHUTDOWN"; + + public static void main(String[] args) { + HttpServer server = new HttpServer(); + // ȴ + server.await(); + } + + public void await() { + ServerSocket serverSocket = null; + int port = 8080; + try { + // ׽ֶ + serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1")); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + + // ѭȴ + while (true) { + Socket socket = null; + InputStream input = null; + OutputStream output = null; + try { + // ȴӣӳɹ󣬷һSocket + socket = serverSocket.accept(); + input = socket.getInputStream(); + output = socket.getOutputStream(); + + // Request󲢽 + Request request = new Request(input); + request.parse(); + + // Response + Response response = new Response(output); + response.setRequest(request); + + // ȡurl + String url = request.getUri(); + + // xml + /* + * Boolean canRead = findurl(url); + * + * if(canRead) { + * //xmlõ + * String servletName = getServeletName(url); + * ServletProcessor processor = new ServletProcessor(); + * processor.process(request,response,servletName); + * } + * else { + * StaticResourceProcessor + * processor = new StaticResourceProcessor(); + * processor.process(request, response); } + */ + String filename = System.getProperty("user.dir")+ File.separator +"jsp" + File.separator + url; + if(new File(filename).exists()) + { + // תjsp + jspReader jsp = new jspReader(url.split("/")[1]); + ServletProcessor processor = new ServletProcessor(); + processor.process(request,response,jsp.getServletName()); + } + else + { + System.out.println("Ҳļ"); + } + + + // ر socket + socket.close(); + + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + } + + public Boolean findurl(String url) { + Element element = null; + // ʹþ· + File f = new File("web.xml"); + + DocumentBuilder db = null; + DocumentBuilderFactory dbf = null; + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + Document dt = db.parse(f); + + // õһelmentԪ + element = dt.getDocumentElement(); + + // øԪµӽڵ + NodeList childNodes = element.getChildNodes(); + + NodeList theNodeList = null; + + // Щӽڵ + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһservelet-mappinguri + if ("servlet-mapping".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("url-pattern".equals(detail.getNodeName())) { + // ƥurl + if (url.equals(detail.getTextContent()))// ƥ䵽true + return true; + } + + } + } + } + } + + catch (Exception e) { + System.out.println(e.toString()); + } + + return false; + } + + public String getServeletName(String url) { + String ServeletName = null; + + Element element = null; + // ʹþ· + File f = new File("web.xml"); + + DocumentBuilder db = null; + DocumentBuilderFactory dbf = null; + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + Document dt = db.parse(f); + + // õһelmentԪ + element = dt.getDocumentElement(); + + // øԪµӽڵ + NodeList childNodes = element.getChildNodes(); + + NodeList theNodeList = null; + + // Щӽڵ + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһservelet-mappinguri + if ("servlet-mapping".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("url-pattern".equals(detail.getNodeName())) { + // ƥurl + if (url.equals(detail.getTextContent()))// ƥ䵽ýڵȡ + theNodeList = nodeDetail; + } + + } + } + } + + String Sname = null; + // ȡ + for (int j = 0; j < theNodeList.getLength(); j++) { + Node detail = theNodeList.item(j); + + if ("servlet-name".equals(detail.getNodeName())) // ƥname + { + Sname = detail.getTextContent(); + } + + } + + NodeList theNodeList1 = null; + + // ٴαƥӦservelet-class + for (int i = 0; i < childNodes.getLength(); i++) { + // ÿӦλiĽ + Node node1 = childNodes.item(i); + + // ƥÿһserveleturi + if ("servlet".equals(node1.getNodeName())) { + + NodeList nodeDetail = node1.getChildNodes(); + + for (int j = 0; j < nodeDetail.getLength(); j++) { + Node detail = nodeDetail.item(j); + + if ("servlet-name".equals(detail.getNodeName())) // ƥurlӦ + if (Sname.equals(detail.getTextContent()))// ƥ䵽ýڵȡ + theNodeList1 = nodeDetail; + } + } + } + // ȡserveletname + for (int j = 0; j < theNodeList1.getLength(); j++) { + Node detail = theNodeList1.item(j); + + if ("servlet-class".equals(detail.getNodeName())) // ƥ + { + ServeletName = detail.getTextContent(); + } + + } + } + + catch (Exception e) { + e.printStackTrace(); + } + + return ServeletName; + } +} diff --git a/14301056/src/jsp/Request.java b/14301056/src/jsp/Request.java new file mode 100755 index 0000000..6185a1d --- /dev/null +++ b/14301056/src/jsp/Request.java @@ -0,0 +1,188 @@ +package jsp; + +import java.io.InputStream; +import java.io.IOException; +import java.io.BufferedReader; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; + +public class Request implements ServletRequest { + + private InputStream input; + private String uri; + + public Request(InputStream input) { + this.input = input; + } + + public String getUri() { + return uri; + } + /** + * + * requestStringʽ£ + * GET /index.html HTTP/1.1 + * Host: localhost:8080 + * Connection: keep-alive + * Cache-Control: max-age=0 + * ... + * úĿľΪ˻ȡ/index.htmlַ + */ + private String parseUri(String requestString) { + int index1, index2; + index1 = requestString.indexOf(' '); + if (index1 != -1) { + index2 = requestString.indexOf(' ', index1 + 1); + if (index2 > index1) + return requestString.substring(index1 + 1, index2); + } + return null; + } + //InputStreamжȡrequestϢrequestлȡuriֵ + public void parse() { + // Read a set of characters from the socket + StringBuffer request = new StringBuffer(2048); + int i; + byte[] buffer = new byte[2048]; + try { + i = input.read(buffer); + } catch (IOException e) { + e.printStackTrace(); + i = -1; + } + for (int j = 0; j < i; j++) { + request.append((char) buffer[j]); + } + System.out.print(request.toString()); + uri = parseUri(request.toString()); + } + + /* implementation of the ServletRequest */ + public Object getAttribute(String attribute) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public String getRealPath(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public boolean isSecure() { + return false; + } + + public String getCharacterEncoding() { + return null; + } + + public int getContentLength() { + return 0; + } + + public String getContentType() { + return null; + } + + public ServletInputStream getInputStream() throws IOException { + return null; + } + + public Locale getLocale() { + return null; + } + + public Enumeration getLocales() { + return null; + } + + public String getParameter(String name) { + return null; + } + + public Map getParameterMap() { + return null; + } + + public Enumeration getParameterNames() { + return null; + } + + public String[] getParameterValues(String parameter) { + return null; + } + + public String getProtocol() { + return null; + } + + public BufferedReader getReader() throws IOException { + return null; + } + + public String getRemoteAddr() { + return null; + } + + public String getRemoteHost() { + return null; + } + + public String getScheme() { + return null; + } + + public String getServerName() { + return null; + } + + public int getServerPort() { + return 0; + } + + public void removeAttribute(String attribute) { + } + + public void setAttribute(String key, Object value) { + } + + public void setCharacterEncoding(String encoding) + throws UnsupportedEncodingException { + } + +@Override +public String getLocalAddr() { + // TODO Auto-generated method stub + return null; +} + +@Override +public String getLocalName() { + // TODO Auto-generated method stub + return null; +} + +@Override +public int getLocalPort() { + // TODO Auto-generated method stub + return 0; +} + +@Override +public int getRemotePort() { + // TODO Auto-generated method stub + return 0; +} + +} diff --git a/14301056/src/jsp/Response.java b/14301056/src/jsp/Response.java new file mode 100755 index 0000000..eb6bd12 --- /dev/null +++ b/14301056/src/jsp/Response.java @@ -0,0 +1,115 @@ +package jsp; + +import java.io.OutputStream; +import java.io.IOException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.File; +import java.io.PrintWriter; +import java.util.Locale; +import javax.servlet.ServletResponse; +import javax.servlet.ServletOutputStream; + +public class Response implements ServletResponse { + + private static final int BUFFER_SIZE = 1024; + Request request; + OutputStream output; + PrintWriter writer; + + public Response(OutputStream output) { + this.output = output; + } + + public void setRequest(Request request) { + this.request = request; + } + + //webļд뵽OutputStreamֽ +//webļд뵽OutputStreamֽ +public void sendStaticResource() throws IOException { +byte[] bytes = new byte[BUFFER_SIZE]; +FileInputStream fis = null; +try { +/* request.getUri has been replaced by request.getRequestURI */ +File file = new File(Constants.WEB_ROOT, request.getUri()); +fis = new FileInputStream(file); +/* +* HTTP Response = Status-Line(( general-header | response-header | +* entity-header ) CRLF) CRLF [ message-body ] Status-Line = +* HTTP-Version SP Status-Code SP Reason-Phrase CRLF +*/ +int ch = fis.read(bytes, 0, BUFFER_SIZE); +while (ch != -1) { +output.write(bytes, 0, ch); +ch = fis.read(bytes, 0, BUFFER_SIZE); +} +} catch (FileNotFoundException e) { +String errorMessage = "HTTP/1.1 404 File Not Found\r\n" + + "Content-Type: text/html\r\n" + "Content-Length: 23\r\n" + + "\r\n" + "

File Not Found

"; +output.write(errorMessage.getBytes()); +} finally { +if (fis != null) +fis.close(); +} +} + + + /** implementation of ServletResponse */ + public void flushBuffer() throws IOException { + } + + public int getBufferSize() { + return 0; + } + + public String getCharacterEncoding() { + return null; + } + + public Locale getLocale() { + return null; + } + + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + public PrintWriter getWriter() throws IOException { + // autoflush is true, println() will flush, + // but print() will not. + writer = new PrintWriter(output, true); + return writer; + } + + public boolean isCommitted() { + return false; + } + + public void reset() { + } + + public void resetBuffer() { + } + + public void setBufferSize(int size) { + } + + public void setContentLength(int length) { + } + + public void setContentType(String type) { + } + + public void setLocale(Locale locale) { + } + +public String getContentType() { + return null; +} + +public void setCharacterEncoding(String arg0) { +} + +} diff --git a/14301056/src/jsp/ServletProcessor.java b/14301056/src/jsp/ServletProcessor.java new file mode 100755 index 0000000..7dc2ae2 --- /dev/null +++ b/14301056/src/jsp/ServletProcessor.java @@ -0,0 +1,56 @@ +package jsp; + +import java.net.URL; +import java.net.URLClassLoader; +import java.net.URLStreamHandler; +import java.io.File; +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import jsp.Request; +import jsp.Response; + +public class ServletProcessor { + + public void process(Request request, Response response,String servletName) { + + //ڴָJARļĿ¼ + URLClassLoader loader = null; + try { + URLStreamHandler streamHandler = null; + // + System.out.println(System.getProperty("user.dir")+ File.separator+ "work" + File.separator); + loader = new URLClassLoader(new URL[]{new URL(null, "file:" + + System.getProperty("user.dir")+ File.separator+ "work" + File.separator, + streamHandler)}); + } catch (IOException e) { + System.out.println(e.toString()); + } + + Class myClass = null; + try { + //ضӦservlet + myClass = loader.loadClass(servletName); + } catch (ClassNotFoundException e) { + System.out.println(e.toString()); + } + + Servlet servlet = null; + + try { + //servletʵ + servlet = (Servlet) myClass.newInstance(); + //ִervletservice + servlet.service((ServletRequest) request,(ServletResponse) response); + } catch (Exception e) { + System.out.println(e.toString()); + } catch (Throwable e) { + System.out.println(e.toString()); + } + + } + +} diff --git a/14301056/src/jsp/StaticResourceProcessor.java b/14301056/src/jsp/StaticResourceProcessor.java new file mode 100755 index 0000000..894e6ef --- /dev/null +++ b/14301056/src/jsp/StaticResourceProcessor.java @@ -0,0 +1,15 @@ +package jsp; + +import java.io.IOException; + +public class StaticResourceProcessor { + + public void process(Request request, Response response) { + try { + response.sendStaticResource(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + \ No newline at end of file diff --git a/14301056/src/jsp/aa.java b/14301056/src/jsp/aa.java new file mode 100755 index 0000000..e69de29 diff --git a/14301056/src/jsp/jspReader.java b/14301056/src/jsp/jspReader.java new file mode 100755 index 0000000..ca211c8 --- /dev/null +++ b/14301056/src/jsp/jspReader.java @@ -0,0 +1,193 @@ +package jsp; + +import java.io.*; +import java.net.URLClassLoader; +import java.util.Arrays; + +import javax.tools.*; + +public class jspReader { + + private String jspName; + private String jspContent = null; + private String ServeletContent = null; + + public jspReader(String uri) { + jspName = uri; + Read(); + makeServlet(); + } + + public void init() { + + } + + public void Read() { + File f = new File(System.getProperty("user.dir") + File.separator + "jsp" + File.separator + jspName); + + BufferedReader br; + + try { + br = new BufferedReader(new FileReader(f)); + + String line = br.readLine(); + + if(line.contains("<%@")) + { + line = "<% response.setContentType(\"text/html; charset=gb2312\");%>"; + line = line.replace("\"", "&&&&"); + } + + jspContent = line; + + while ((line = br.readLine()) != null) { + + if(line.contains("<%=")) + { + line = line.replace("<%=", "$$out.println("); + line = line.replace("%>", ");&&"); + line = line.replace("\"", "&&&&"); + } + + jspContent = jspContent + " " + line; + } + + br.close(); + // System.out.println(jspContent); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(jspContent); + } + + public void makeServlet() { + // ȡ4ļ + File f1 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_1.txt"); + File f2 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_2.txt"); + File f3 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_3.txt"); + File f4 = new File(System.getProperty("user.dir") + File.separator + "part" + File.separator + "part_4.txt"); + + BufferedReader br1, br2, br3, br4; + + try { + // part4 + br4 = new BufferedReader(new FileReader(f4)); + + String line = null; + + String[] sign = new String[7]; + + sign[0] = br4.readLine(); + sign[1] = "\n" + br4.readLine() ; + sign[2] = sign[0] + br4.readLine(); + sign[3] = br4.readLine(); + sign[4] = br4.readLine(); + sign[5] = br4.readLine(); + sign[6] = br4.readLine(); + + br4.close(); + // + // 滻 + // String ServeletContent1 = jspContent.replace(sign[5], sign[6]); + String ServeletContent1 = jspContent.replace("$$out.println(", sign[2]); + ServeletContent1 = ServeletContent1.replace(");&&",");" + sign[1] ); + ServeletContent1 = ServeletContent1.replace("<%", sign[0]); + ServeletContent1 = ServeletContent1.replace("%>", sign[1]); + ServeletContent1 = ServeletContent1.replace("&&&&", sign[5]); + + + // import-class + br1 = new BufferedReader(new FileReader(f1)); + + line = null; + + ServeletContent = br1.readLine(); + + while ((line = br1.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br1.close(); + // + + ServeletContent = ServeletContent + "\n" + jspName.split(".jsp")[0] + "Servlet\n"; + // System.out.println(jspName.split(".jsp")[0]); + + // part2 + br2 = new BufferedReader(new FileReader(f2)); + + line = null; + + ServeletContent = ServeletContent + br2.readLine(); + + while ((line = br2.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br2.close(); + // + ServeletContent = ServeletContent + ServeletContent1; + // part3 + br3 = new BufferedReader(new FileReader(f3)); + + line = null; + + ServeletContent = ServeletContent + br3.readLine(); + + while ((line = br3.readLine()) != null) { + + ServeletContent = ServeletContent + "\n" + line; + } + + br3.close(); + // + + + + // System.out.println(ServeletContent); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // java + File f = new File(System.getProperty("user.dir") + File.separator + "work" + File.separator + + jspName.split(".jsp")[0] + "Servlet.java"); + try { + if (!f.exists()) { + f.createNewFile(); + } + FileWriter fw = new FileWriter(f); + + fw.write(ServeletContent); + + fw.close(); + + String dir = System.getProperty("user.dir") + File.separator+ "work"; + String filename = jspName.split(".jsp")[0] + "Servlet.java"; + + // ϵͳ + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + + StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); + // Դļ + Iterable fileObject = fileManager.getJavaFileObjects(new File(dir,filename)); + // + JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d", "./work"), + null, fileObject); + task.call(); + + fileManager.close(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public String getServletName() + { + return jspName.split(".jsp")[0] + "Servlet"; + } +}