Home > Back-end >  Null pointer how ah
Null pointer how ah

Time:09-30

Java. Lang. NullPointerException
The Servlet LoginServlet. DoPost (LoginServlet. Java: 43)
Javax.mail. Servlet. HTTP. HttpServlet. Service (660) the HttpServlet. Java:
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 741)
Org, apache tomcat, websocket server. WsFilter. DoFilter (53) WsFilter. Java:

CodePudding user response:


Yes ah, 43

CodePudding user response:

There is a function inside the eclipse debug

CodePudding user response:

Server error,

CodePudding user response:

String name=request. The getParameter (" userName ")!=null? Request. The getParameter (" userName ") : "";
String name=request. The getParameter (" PWD ")!=null? Request. The getParameter (" PWD ") : "";
The above 2 lines replacing the try

CodePudding user response:

Sentenced to empty can try (null==name | | "". The equals (name))

CodePudding user response:

Use the StringUtils. IsBank (name)

CodePudding user response:

Request. The getParameter return originally is likely to be empty, the name and the PWD is likely to be null, use null. IsEmpty () must be submitted to the null pointer exception
It is best to use StringUtils. IsBank (name) to null | | an empty string

CodePudding user response:

refer to 6th floor XmCui response:
use StringUtils. IsBank (name)



Spell wrong StringUtils. IsBlank

The Commons bag

 

Org.apache.com mons
Commons - lang3 & lt;/artifactId>
3.8.1 & lt;/version>

CodePudding user response:

Name. IsEmpty ()
Null==name directly,

CodePudding user response:

The name or the PWD is null, general judgment string is empty to write the name!=null & amp; & ! Name. IsEmpty (), usually used in the Commons - lang StringUtils. IsNotBlank to judge

CodePudding user response:

StringUtils. IsEmpty (name) | | StringUtils. IsEmpty try (PWD)

CodePudding user response:

/* *
* Returns {@ code true} the if, and only if, {@ # link length ()} is {@ code 0}.
*
* @ return {@ code true} if {@ # link length ()} is {@ code 0}, otherwise
* {@ code false}
*
* @ since 1.6
*/
Public Boolean isEmpty () {
The return value. The length==0;
}
To know how isEmpty source before use, if your value is not passed, then the value is null if held null Pointers, null how length??????? So you'll have to figure out whether the empty, is not to judge isEmpty when empty

CodePudding user response:

Of course use StringUtils isEmpty seems to be no problem, because the source code is as follows:
Public static Boolean isEmpty (CharSequence cs) {
Cs==null return | | cs. The length ()==0;
}
Judge it null!
So you can change StringUtils. IsEmpty (name)
  • Related