缺少字符串java中的字符

问题描述 投票:0回答:2

[我正在尝试用http框架实现Java服务器,我有几个URI:/login.jsp和/logout.jsp,可以在http格式的请求URi中找到。

[当我将注销请求发送到服务器时,我将其发送给邮件头,如下所示:

Cookie: user_auth="SomeCookie".

这里是代码:

public HttpMessage nextMessage() {
    if (!isAlive()) {
        try {
            throw new IOException("Tokenizer is Closed");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Return String
    HttpMessage newMessage = null;
    String output = null;
    StringBuilder stringBuilder = new StringBuilder();
    try {
        int c;

        while ((c = this.fInputStream.read()) != -1) {
            if (c == this.fDelimiter)
                break;
            else
                stringBuilder.append((char) c);
        }
        // Create an HttpMessage from the information received
        output = stringBuilder.toString();

    } catch (IOException e) {
        this.fClosed = true;
        try {
            throw new IOException("Connection is Dead");
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    newMessage = parseHttp(output);
    return newMessage;
}

parseHttp方法将类型和标题分开。

但是问题是将login操作发送到服务器后,如果我尝试发送logout操作,则存储在字符串生成器中的已解析信息缺少字符(更具体地说,RequestType,RequestURI和HttpVersion)丢失,只能找到标题。

此外,如果我尝试打印我看到应该在帧中的所有字符时从inputStream接收到的每个字符,则>

[我正在尝试用http框架实现Java服务器,我有几个URI:/login.jsp和/logout.jsp,可以在http格式的请求URi中找到。当我将注销请求发送到...

java tcp server tokenize stringbuilder
2个回答
0
投票

您确定要break;行而不是continue;中断将导致while循环退出,而使用continue将仅跳过else并运行while循环的下一次迭代。


0
投票
import java.util.*;
public class MissChars
{
 public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String str=sc.nextLine();
    StringBuffer sb=new StringBuffer();
    char c[]=str.toCharArray();
    LinkedHashSet<Character> set=new LinkedHashSet<Character>();
    for(int i=0;i<c.length;i++)
      set.add(c[i]);
    for(char cc:set)
      sb.append(cc);
    String sss=new String(sb);
    char arr[]=sss.toCharArray();
    for(char i='a';i<='z';i++)
    {
        for(int j=0;j<arr.length;j++)
        {
            if(i!=arr[j])
                count++;
            if(count==arr.length)
              System.out.print(i);
        }
        count=0;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.