首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse不能建立异常jsp页面(初学者有关问题)

2012-01-11 
求助:eclipse不能建立错误jsp页面(菜鸟问题)在Eclipse创建Webprojectnametest,然后写了一个price.jsp和一

求助:eclipse不能建立错误jsp页面(菜鸟问题)
在Eclipse创建Web   project   name=test,然后写了一个   price.jsp   和一个   excep.jsp

                                                price.jsp
<%@   page   errorPage= "excep.jsp "%>
<%
String   strPrice=request.getParameter( "price ");
double   price=Double.parseDouble(strPrice);

out.println( "Total   price   =   "+price*3);
  %>

                                                excep.jsp
<%@   page   isErrorPage= "true "%>
<%
out.println( "exception.toString(): ");
out.println( " <br> ");
out.println(exception.toString());
out.println( " <p> ");

out.println( "exception.getMessage(): ");
out.println( " <br> ");
out.println(exception.getMessage());
%>

运行时:   http://localhost:8080/Test/price.jsp?price=100
会输出:Total   price   =   300.0  

但是输入:   http://localhost:8080/Test/price.jsp?price=abc
出现不了正常的错误页面   提示的是无法显示网页

在   excep.jsp中,任意修改一处地方,运行让tomcat报错,然后在改回来,输入
http://localhost:8080/Test/price.jsp?price=abc
才出现正常的错误页面:

exception.toString():  
java.lang.NumberFormatException:   For   input   string:   "abc "  
exception.getMessage():  
For   input   string:   "abc "  

如果再输入http://localhost:8080/Test/price.jsp?price=abcd
有会出现无法显示页面,然后要重复上面的步骤才可以正常的运行错误页面

不知道为什么会这样子,希望有高手指点指点~~谢谢!


[解决办法]
在price.jsp中有这么一句,double price=Double.parseDouble(strPrice);你应该先判断是否为空,再格式数字类型,否则若传入的不是数字类型就会报NumberFormatException.errorPage是用来处理当前页面抛出但未捕获的任何异常,而parseDouble()应该在底层已经作了相关处理.估计是这个原因~~~

热点排行