package servletbean;
import javax.swing.JOptionPane;
public class myfilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
response.setContentType("text/html");
response.setCharacterEncoding("GB2312");
PrintWriter out=response.getWriter();
String name="";
String age="";
int age1;
name=request.getParameter("name");
age=request.getParameter("age");
RequestDispatcher dispatch=request.getRequestDispatcher("erroroutput.jsp"); if(name==null||name==""||name==" "||age==null)
{
JOptionPane.showMessageDialog(null,"用户名和年龄输入错误!");
dispatch.forward(request, response);
return;
}
else
{
try
{
age1=Integer.parseInt(age);
}
catch(Exception e)
{
//JOptionPane.showMessageDialog(null,"年龄必须为数字!");
dispatch.forward(request,response);
return;//如果是错误页面就到erroroutput.jsp中
}
}
chain.doFilter(request, response);//这里表示是正确的,也就是说,他回去找下一个链,但是它下面已经没有了,所以就会去跳转页面了,此时要跳转的页面就是action="output.jsp"了。
}
}