java类中抛出的异常如何显示在JSP页面中

dreamflying6 2008-09-08 04:01:35
我想用do.jsp来处理上传的文件,读取文件内容,如果文件不合规范就显示显示抛出的异常。把clspenxml.deal处理文件时抛出的异常显示在do.jsp页面中,如何显示?
try
{
clspenxml.deal( "d:\\upload\\" + myFile.getFileName() , comcd.trim() , userid.trim() , "CP",appcom.trim());
}
catch (Exception e)
{
out.println("Unable to deal the file.<br>");
out.println("Error : " + e.toString());
}

方法clspenxml.deal()在另外一个class文件中
public void deal( String infile ,String incom , String inuser , String msgtype,String company )
{
String filetype = "";
try
{

root = getElement( infile );

if ( root == null )
{
throw new Exception("报文格式有误:root is null ");
}
........

}
catch ( SQLException sqle )
{
System.out.println(" sqle: " + sqle.getMessage() );
}
catch (Exception ex1 )
{
System.out.println(" Exception: " + ex1.getMessage() );

}
}
就是如何把象throw new Exception("报文格式有误:root is null ");这样的显示在do.jsp页面中。
...全文
575 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
software_jianghai 2008-09-08
  • 打赏
  • 举报
回复
放到request即可
  • 打赏
  • 举报
回复
catch的时候 截取异常内容 session保存 然后调用
foundercy_weng 2008-09-08
  • 打赏
  • 举报
回复
做一个检查不就得了检查文件格式是否满足你的要求,如果不满足提示出来!!
缘来是你 2008-09-08
  • 打赏
  • 举报
回复
public String deal( String infile ,String incom , String inuser , String msgtype,String company )
{
String filetype = "";
try
{

root = getElement( infile );

if ( root == null )
{
return "报文格式有误:root is null ";
}
........

}
catch ( SQLException sqle )
{
return " sqle: " + sqle.getMessage() ;
}
catch (Exception ex1 )
{
return " Exception: " + ex1.getMessage() ;

}
return "pass";
}
dreamflying6 2008-09-08
  • 打赏
  • 举报
回复
问题是void不能返回值!
luhao 2008-09-08
  • 打赏
  • 举报
回复
可以把函数变一下
return 一个String回去

public void deal( String infile ,String incom , String inuser , String msgtype,String company )
{
String filetype = "";
try
{

root = getElement( infile );

if ( root == null )
{
return "报文格式有误:root is null ";
}
........

}
catch ( SQLException sqle )
{
return " sqle: " + sqle.getMessage() ;
}
catch (Exception ex1 )
{
return " Exception: " + ex1.getMessage() ;

}
return "pass";
}
然后你JSP上做判断

如果不是pass 那就是出错啊
缘来是你 2008-09-08
  • 打赏
  • 举报
回复
方法clspenxml.deal()你可以改他的返回类型为String 把异常的值作为返回值 jsp页面不就得到了 呵呵

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧