📄 httprequest.java
字号:
package section18;
import java.util.LinkedList;
import java.util.List;
public class HTTPRequest {
List lines=new LinkedList();
public HTTPRequest() {
super();
// TODO Auto-generated constructor stub
}
public void addLine(String line)
{
lines.add(line);
}
boolean isGetRequest()
{
if(lines.size()>0)
{
String firstLine=(String)lines.get(0);
if(firstLine.length()>0)
if(firstLine.substring(0,3).equalsIgnoreCase("GET"))
return true;
}
return false;
}
String getFileName()
{
if(lines.size()>0)
{
String firstLine=(String)lines.get(0);
String fileName=firstLine.substring(firstLine.indexOf(" ")+1);
int n=fileName.indexOf(" ");
if(n!=-1)fileName=fileName.substring(0,n);
try{
if(fileName.charAt(0)=='/')fileName=fileName.substring(1);
}
catch(StringIndexOutOfBoundsException ex){}
if(fileName.equals(""))fileName="index.htm";
if(fileName.charAt(fileName.length()-1)=='/')
fileName+="index.htm";
return fileName;
}else return "";
}
void log()
{
System.out.println("Received the following request:");
for(int i=0;i<lines.size();i++)
System.out.println((String)lines.get(i));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -