Java if/else behaving strangely

后端 未结 4 727
日久生厌
日久生厌 2021-01-26 18:50

I\'m a real newbie to java, so please excuse me if this is a hopelessly straightforward problem.

I have the following from my java game server:

// Get in         


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 19:36

    From the information added in your comments it seems that what will be happening is the client is sending a single character (e.g. 'n'). The line

    line.substring(0,3).equals("GET")||line.substring(0,4).equals("POST"))
    

    will be executed, but since line is only a single character line.substring(0,3) will throw a StringIndexOutOfBoundsException. Either this is causing your program to fail and you haven't mentioned that. Or you have some exception handling going on in another part of your code that you haven't shown and this is either supressing the error or printing a log line or something and again you haven't mentioned this (or noticed it).

    Try replacing substring().equals with startsWith

提交回复
热议问题