[英]java - creating web server - handling incoming http requests
I am trying to write a web server in Java (this is my first time so an extremely simple web server). 我正在尝试用Java编写Web服务器(这是我第一次使用非常简单的Web服务器)。 I am not sure how to process the http get and post requests.
我不确定如何处理http的get和post请求。
Write now all I have is a loop with a server socket excepting connections and using a BufferedReader to take in the incoming message (as text). 现在我写的就是一个带有服务器套接字的循环(除了连接),并使用BufferedReader接收传入的消息(作为文本)。
I know that you can extend a Servlet class and make use of 我知道您可以扩展Servlet类并利用
protected void doGet(HttpServletRequest servlet_request, HttpServletResponse servlet_response)
, and protected void doGet(HttpServletRequest servlet_request, HttpServletResponse servlet_response)
和 protected void doPost(HttpServletRequest servlet_request, HttpServletResponse servlet_response)
but I cannot work out how to transform/extract a raw incoming message from the socket into the parameters needed for the doGet() and doPost(). 但是我无法解决如何将套接字中的原始传入消息转换/提取为doGet()和doPost()所需的参数。
Would someone be able to give a basic example and/or explanation of what to do? 有人能够给出基本示例和/或说明如何做吗?
Many thanks 非常感谢
Also, as an after thought, would it be simple to extend the web server to process JSP pages? 此外,经过一番思考,将Web服务器扩展为处理JSP页面是否简单?
Any help is greatly appreciated. 任何帮助是极大的赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.