Learning record 08 --- servlet repair some minor problems

Today, after rewriting DBTools, before trying to write back-end change to change, and found that there is a small problem

If the value is less when a parameter will be reported null pointer exception, the final approach fix is ​​to determine whether or not empty, then give value

Take the example of insertion to do it, modified in the same way to modify the line

1  // Create a Student object data store 
2          Student info = new new Student ();
 . 3  
. 4          // Get pass over the front end of the parameter 
. 5          IF (! Request.getParameter ( "name") = null )
 . 6              info.setName (Request. the getParameter ( "name" ));
 . 7          IF ! (request.getParameter ( "pwd") = null )
 . 8              info.setPwd (request.getParameter ( "pwd" ));
 . 9          IF (request.getParameter ( "Age")! = null )
 10              info.setAge (the Integer.parseInt (request.getParameter ( "Age" )));
11         if(request.getParameter("address")!=null)
12             info.setAddress(request.getParameter("address"));
13         if(request.getParameter("sex")!=null)
14             info.setSex(request.getParameter("sex"));
15         if(request.getParameter("classid")!=null)
16             info.setClassid(Integer.parseInt(request.getParameter("classid")));

As above so you can avoid this problem

 

Guess you like

Origin www.cnblogs.com/huajidafahao/p/11290515.html