1) Scene: use the request object under the HttpServletRequest package to perform the query request.getAttribute () and request.setAttribute () null pointer exception when assigning value
2) reason:
error example code:
because the value of provinceid is not assigned to the page before the jump, and then the value is assigned to the control layer here, but there is no provinceid object in the request object at all, so the tostring() of an empty object will definitely cause an error
3) Solution: however, we need to get the value in the form of string to prevent the occurrence of null pointer (that is, provinceid does not exist in the request object at all). We need to judge whether the request object is null
if(request.getAttribute("provinceId")!=null){
//Execute the corresponding operation e.g. output
String provinceId=request.getAttribute("provinceId").toString();
System.out.println(provinceId)
}
Reminder: when the four common value taking methods in the controller operate, the received object must be judged to be null, and the object cannot be directly toString
Similar Posts:
- [Solved] Java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
- Several cases of error reporting in java.lang.nullpointerexception
- Runtime error: invalid memory address or nil pointer dereference [How to Solve]
- com.sun.jdi.InvocationException occurred invoking method
- JAVA set to determine the null: List.isEmpty() & null == List && List.size()==0
- How to Solve Console error: index: 0, size: 0
- Convert Object to List>, avoiding Unchecked cast: ‘java.lang.Object’ to ‘java.util.List
- [Solved] Cannot call sendRedirect() after the response has been committed
- [Solved] Mvel user-defined function error: duplicate function
- The difference between system.err.println and system.out.println