このコードでは、Personal personal=new Personal();
オブジェクトを使用しました。 しかし、ここではnullポインタ例外を処理したいと思います。私の問題を助けてください。jspのforループ内でNullPointerExceptionを処理する方法は?
<%
if(personal!=null) {
String sNo[] = personal.getsNo().split(",") ;
String hsnCode[]=personal.getHsnCode().split(",");
String modelNumber[] = personal.getModelNumber().split(",") ;
String serialNumber[] = personal.getSerialNumber().split(",") ;
String labourFree[] = personal.getLabourFree().split(",") ;
String rate[] = personal.getRate().split(",") ;
String qty[] = personal.getQuantity().split(",") ;
String gstSelect[] = personal.getGst().split(",") ;
String amount[] = personal.getAmount().split(",") ;
if(modelNumber.length>0){
for(int i=0;i<modelNumber.length;i++){
%>
<tr>
<td> <%=sNo[i] %></td>
<td> <%=hsnCode[i]%></td>
<td> <%=modelNumber[i] %></td>
<td> <%=serialNumber[i] %></td>
<%-- <td> <%=labourFree[i] %></td> --%>
<td> <%=rate[i] %></td>
<td> <%=qty[i] %></td>
<td> <%=gstSelect[i] %></td>
<td> <%=amount[i] %></td>
</tr>
<%
}
}
}
%>
私は地元にこのコードを使用していますし、私はどんなexcpetionを得るが、私がしたいだけで、サーバ
スタックトレース、
org.apache.jasper.JasperException: An exception occurred processing JSP page /completeDetail.jsp at line 124
121: <%
122:
123: if(personal!=null) {
124: String sNo[] = personal.getsNo().split(",") ;
125: String hsnCode[]=personal.getHsnCode().split(",");
126: String modelNumber[] = personal.getModelNumber().split(",") ;
127: String serialNumber[] = personal.getSerialNumber().split(",") ;
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
org.apache.jsp.completeDetail_jsp._jspService(completeDetail_jsp.java:211)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.59 logs.
https://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files?rq=1 –