登录界面:input.jsp

  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <HTML> 
  3. <HEAD> 
  4. <TITLE>登录页面</TITLE> 
  5. </HEAD> 
  6. <BODY> 
  7. <BR> 
  8. <FORM action="sendRedirect.jsp" method=post name=form1> 
  9. <P>姓名:<INPUT name=inputName ></P> 
  10. <P>密码:<INPUT name=inputPass></P> 
  11. <INPUT name=submit type=submit value=登录> 
  12. </FORM> 
  13. </BODY> 
  14. </HTML> 

处理页面:sendRedirect.jsp

  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <%@ page language="java" %> 
  3. <
  4. String Name = request.getParameter("inputName"); 
  5. String Pass = request.getParameter("inputPass"); 
  6. if(Name.equals("") || Pass.equals("")) 
  7.     response.sendRedirect("error.jsp");  
  8. %> 
  9. <HTML> 
  10. <HEAD> 
  11. <TITLE>网页引导</TITLE> 
  12. </HEAD> 
  13. <BODY> 
  14. <BR> 
  15. <P>您输入的姓名是: 
  16. <%= Name %> 
  17. </P> 
  18. <P>您输入的密码为: 
  19. <%= Pass %> 
  20. </P> 
  21. </BODY> 
  22. </HTML> 

error.jsp

  1. <%@ page contentType="text/html; charset=GB2312" %> 
  2. <HTML> 
  3. <HEAD> 
  4. <TITLE>网页引导</TITLE> 
  5. </HEAD> 
  6. <BODY> 
  7.  
  8. <BR> 
  9. <FORM action="sendRedirect.jsp" method=post name=form1> 
  10. <font size=5 color=red> 
  11. 你输入的信息不完整,请重新输入! 
  12. </font> 
  13. <br> 
  14. <P>姓名 : <INPUT name=inputName ></P> 
  15. <P>密码 : <INPUT name=inputPass ></P> 
  16. <INPUT name=submit type=submit value=登录> 
  17. </FORM> 
  18. </BODY> 
  19. </HTML> 

结果:


你输入的信息不完整,请重新输入!

姓名 :

密码 :

对于错误页面的处理,如果想加入自定义的信息,比如 你输入的信息不完整,请重新输入!,处理过程比较麻烦,首先判断请求信息是否为空,如果为空,跳转到错误页面。 如果我们用 struts2 以后,对于错误页面的处理将非常方便。