日期:2014-05-18  浏览次数:20660 次

求助: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
有会出现无法显示页面,然后要重复上面的步骤才可以正常的运行错误页面

不知道为什么会这样子,希望有高手指点指点,最好告诉我修改代码~~谢谢!

------解决方案--------------------
需要自己在程序中进行try{} catch{},在catch{}中抛出异常,在excep.jsp中就可以接收了