jsp空指针异常 求助@@@
取checkbox的值一旦checkbox为null即不选就出现了空指针异常<HTML><BODY><%@pagelanguage="java"%><%@pagecont...
取checkbox的值 一旦checkbox为null 即不选 就出现了空指针异常
<HTML>
<BODY>
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%! String SC[]=new String[8]; String SD[]=new String[8];
int c[]={0,0,0,0,0,0,0,0};int d[]={0,0,0,0,0,0,0,0};
%>
<% SC[0]=request.getParameter("C1");
SC[1]=request.getParameter("C2");
SC[2]=request.getParameter("C3");
%>
<%=SC[0]%>
<%=SC[1]%>
<%
if(SC[0].isEmpty()) out.print("1111111");
%>
</BODY>
</HTML>
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /2.jsp at line 19
16: <%=SC[1]%>
17:
18: <%
19: if(SC[0].equals("on")||SC[0].equals("")) out.print("1111111");
20: %>
21:
22:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
org.apache.jsp._2_jsp._jspService(_2_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs. 展开
<HTML>
<BODY>
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%! String SC[]=new String[8]; String SD[]=new String[8];
int c[]={0,0,0,0,0,0,0,0};int d[]={0,0,0,0,0,0,0,0};
%>
<% SC[0]=request.getParameter("C1");
SC[1]=request.getParameter("C2");
SC[2]=request.getParameter("C3");
%>
<%=SC[0]%>
<%=SC[1]%>
<%
if(SC[0].isEmpty()) out.print("1111111");
%>
</BODY>
</HTML>
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /2.jsp at line 19
16: <%=SC[1]%>
17:
18: <%
19: if(SC[0].equals("on")||SC[0].equals("")) out.print("1111111");
20: %>
21:
22:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
org.apache.jsp._2_jsp._jspService(_2_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs. 展开
2个回答
展开全部
SC[0].equals("on")这句发生了空指针错误,因为String SC[] = new String[8];这句代码将SC中的8个元素全部初始化为null,当你选了checkbox后,SC[0]就不为null,所以也就没有错误了,修改方法如下:
if("on".equalsSC([0])||"".equals(SC[0])) out.print("1111111");
字符串比较时建议将常量写在前面,变量写在后面,这样就可以避免空指针错误。
if("on".equalsSC([0])||"".equals(SC[0])) out.print("1111111");
字符串比较时建议将常量写在前面,变量写在后面,这样就可以避免空指针错误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询