package 复习服务器;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server3 {
public static void main(String[] args) {
String CRLF="\r\n"; //换行
String BWZ=" "; //空格
//创建ServerSocket对象
ServerSocket server=null;
//监听是否有客户端发送请求
Socket clinet=null;
InputStream is=null;
try {
server=new ServerSocket(8080);
clinet = server.accept();
//获取来自浏览器的请求信息
is=clinet.getInputStream();
byte[] buf=new byte[20480];
int len=is.read(buf);
System.out.println(new String(buf,0,len));
/*获取来自浏览器的请求信息*/
StringBuffer sb=new StringBuffer();
StringBuffer sbContent=new StringBuffer();//响应的文本
sbContent.append("<html><head><title>响应结果</title></head>");
sbContent.append("<body>登录成功</body></html>");
//(1)拼接响应头
sb.append("HTTP/1.1").append(BWZ).append(200).append(BWZ).append("ok");
sb.append(CRLF);//换行
sb.append("Content-Type: text/html;charset=utf-8");
sb.append(CRLF);//换行
sb.append("Content-Length:").append(sbContent.toString().getBytes().length).append(CRLF);
sb.append(CRLF);//换行,代表响应头与响应的正文部门之间的空格
sb.append(sbContent);
//通过流输出
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(clinet.getOutputStream(),"utf-8"));
bw.write(sb.toString());
bw.flush();
bw.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
//关闭流
IOaa.a(is,clinet,server);
}
}
}
<html>
<head>
<title>我的第一个heml</title>
</head>
<body>
<h1>heelo word</h1>
<form action=“http://localhost:8000/index.html" method="post">
<p>用户名:<input type="text" id="uname" name="userroname"/></p>
<p>密码:<input type="password" id="pwd" name="password"/></p>
<p>兴趣爱好<input type="checkbox" name="hobby" value="ball"/>球
<input type="checkbox" name="hobby" value="read"/>读书
<input type="checkbox" name="hobby" value="paint"/>画画</p>
<p><input type="submit" value="登录/>"</p>
</form>
</body>
</html>
服务器没有显示
网页显示找不到