public class MyException extends Exception{
public MyExceprion(){
System.out.println("自定义异常");
}
}
try catch(MyException e){
}
当然 你也可以定义一个拦截器放在web.xml
那你就要继续实现 filter 接口了 继承Exception 实现 Filter 接口 那不就完了
implements Filter
public class CharFilter implements Filter {
private String encode;
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain fc) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)resp;
request.setCharacterEncoding(this.encode);
response.setCharacterEncoding(this.encode);
fc.doFilter(request,response);
}
public void init(FilterConfig arg0) throws ServletException {
this.encode=arg0.getInitParameter("encode");//��xml��init-param
}
}
web.xml中 配置拦截器
spring AOP就行了,设置好。。百度里输入springAOP就有答案了,用dom4j也行