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就可以了 POI如何 改变 单元格内容的左右对齐方式?? ArrayList合并相同key项问题 我新来的菜鸟,问个简单的float和double的问题,谢谢大家帮我看看 Hello,World的问题,吐血请大家帮助! 关于数组内的数从小到大排列 请教java读取ftp服务器上的文件的问题 分不够了但是很想知道我用s:property的到了一个1.jpg的字符串怎么将他放到img的src中去 为啥不能画???不用APPLET, 我想在Frame窗口应用程序下怎么画 关于Java能否通过参数来返回数据的问题!!! Java JDK环境变 请教一点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页面,
怎么传递?怎么跳转?
谢谢!