java中throw 怎么传递信息,控制跳转? private String message; if(id == 1) try { throw new BusinessProcessException("业务逻辑执行异常"); } catch (BusinessProcessException e) { e.printStackTrace(); }要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不要在这里catch,让Business.jsp catch 这个异常 public static void main(String[] args){ // TODO Auto-generated method stub try { get(1); } catch (Exception e) { e.printStackTrace(); } } private static void get(int n) throws Exception{ if(n == 1){ throw new Exception(); } } public class Test{ private static void get(int n) throws Exception{ if(n == 1){ throw new Exception(); } }}index.jsp<% try { Test.get(1); response.sendRedirect("success.jsp"); } catch(Exception ex){ response.sendRedirect("error.jsp");}%> 不写 try catch() 提示有错误。要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢! 再jsp页面直接打印吧,用PrintWriter保装一下out,把异常打到out上<% private String message; if(id == 1) try { throw new BusinessProcessException("业务逻辑执行异常"); } catch (BusinessProcessException e) { e.printStackTrace(new java.io.PrintWriter(out)); }%> 参考下面的代码,就不会提示有错了public void method(int id) throws BusinessProcessException{ if(id == 1){ throw new BusinessProcessException("业务逻辑执行异常"); }} public class MyException extends ActionSupport{ private int id; private String message; public String execute() throws Exception{ if(id == 1) throw new BusinessProcessException("业务逻辑执行异常"); else if(id==2) throw new SqlErrorException("操作数据库执行异常"); else if(id==3) throw new TftsException("传输层异常"); else if(id==4) throw new WorkFlowException("工作流交互异常"); else return message; }}要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢! 代码执行到 throw new BusinessProcessException("业务逻辑执行异常")时, 他就已经自动跳转了,如果外层代码有 try{}catch(BusinessProcessException){} 这样的结构,就自动跳转到catch下的代码, 如果没有这样的结构,就会跳出当前方法, 回到调用这个方法的地方, 同样检查有没有try{}catch结构, 没有就继续向上层跳转, 直到有 try{}catch而你这里只需要在Business.jsp中调用这个方法的地方 try{}catch就可以了 关于继承类实例的区别 javaBean 是什么意识? JBuilder和Eclipse哪个好? final方法和private方法的区别! 请问各位高手,用JCreator2.5写程序的时候是否可以设置函数自动提示? 高手指点一下错误提示是什么意思? 100分求关于Assertion的一切资料!!! java中如何读出一个目录下的所有文件和目录? 请问j2sdkee for win的最新版是那个,我装了jdk1。4后装j2skdee1_2_1后启动出错! 怎么将big5转化成gb2312,急! 请教一点equals()方法的问题 求指导,写的程序右下边报错
public static void main(String[] args){
// TODO Auto-generated method stub
try {
get(1);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void get(int n) throws Exception{
if(n == 1){
throw new Exception();
}
}
public class Test{
private static void get(int n) throws Exception{
if(n == 1){
throw new Exception();
}
}
}
index.jsp
<%
try
{
Test.get(1);
response.sendRedirect("success.jsp");
}
catch(Exception ex)
{
response.sendRedirect("error.jsp");
}
%>
要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢!
private String message;
if(id == 1)
try {
throw new BusinessProcessException("业务逻辑执行异常");
} catch (BusinessProcessException e) {
e.printStackTrace(new java.io.PrintWriter(out));
}
%>
if(id == 1){
throw new BusinessProcessException("业务逻辑执行异常");
}
}
public class MyException extends ActionSupport{
private int id;
private String message;
public String execute() throws Exception{
if(id == 1)
throw new BusinessProcessException("业务逻辑执行异常");
else if(id==2)
throw new SqlErrorException("操作数据库执行异常");
else if(id==3)
throw new TftsException("传输层异常");
else if(id==4)
throw new WorkFlowException("工作流交互异常");
else
return message;
}}
要把异常的信息message 传递到Business.jsp页面,
怎么传递?怎么跳转?
谢谢!