问题描述
- 求助!jsp 中substring报错
- String intime=request.getParameter(""d11"");//从文本框中获得的日期,这是从
my97Date控件中获得的值,一开始时为空,点击查询按钮后才会有值
String intime3=intime.substring(5 8);出现下列错误:
type Exception reportmessage An exception occurred processing JSP page /ShowRoom2.jsp at line 80
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 /ShowRoom2.jsp at line 80
77:
78: <%
79: String intime=request.getParameter(""d11"");
80: String intime3=intime.substring(5 8);
81: //if(substring(intime14))
82: //if(intime.substring(0 4).equals(""6""))
83: out.println(""杞?寲鐨勬椂闂达細""+intime3);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:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)root cause
java.lang.NullPointerException
org.apache.jsp.ShowRoom2_jsp._jspService(ShowRoom2_jsp.java:153)
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:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)note The full stack trace of the root cause is available in the Apache Tomcat/7.0.52 logs.
我自己分析了一下原因是第80行出现了空指针,但是我的intime是有值的(“2015-06-15”),就是使用substring报错
有人知道怎么回事吗?
解决方案
intime有没有4个或更多字符,如果没有会报错。
另外,java字符串比较不能用==,应该用equals
解决方案二:
intime有没有4个字符,如果没有会报错。
另外,java字符串比较不能用==,应该用equals
解决方案三:
==和equals的区别
** ==可以比较基本变量和引用变量**
比较基本变量,比较的是具体的值
比较引用变量比较的是地址值
** equals只能比较引用变量**
默认比较的是地址值,但是字符串中已经重写了toString()方法,所以可以比较字符串