JSPÖÐforward()ÓësendRedirect()Çø±ð
response.sendRedirect("display.jsp");
request.getRequestDispatcher("display.jsp").forward(request,response);
jspµÄÒ³ÃæÌøתÓÐÁ½ÖÖ·½·¨£ºRequestDispatcher.forward()·½·¨ºÍHttpServletResponse.sendRedirect()·½·¨¡£
¡¡¡¡ËüÃǵÄÇø±ðÊÇ£º
¡¡¡¡RequestDispatcher.forward()·½·¨½öÊÇÈÝÆ÷ÖпØÖÆȨµÄתÏò£¬ÔÚ¿Í»§¶Ëä¯ÀÀÆ÷µØÖ·À¸Öв»»áÏÔʾ³öתÏòºóµÄµØÖ·£¬ËûÊDz»»á¸Ä±äRequestµÄÖµ£¬Èç¹ûÐèÒªÔÚÏÂÒ»¸öÒ³ÃæÖÐÄÜ´ÓÖлñ ȡеÄÐÅÏ¢µÄ»°£¬¿ÉÒÔRequest.setAttribute()À´·ÅÖÃһЩ±êÖ¾£¬ÕâÑù´ÓÏÂÒ»¸öÒ³ÃæÖлñÈ¡¡£Æäд·¨ÈçÏ£º
¡¡¡¡¡¡ try{
¡¡¡¡¡¡¡¡¡¡ request.getRequestDispatcher("display.jsp").forward(request,response);
¡¡¡¡¡¡ }
¡¡¡¡
¡¡¡¡¡¡ catch(Exception e){
¡¡¡¡
¡¡¡¡¡¡¡¡¡¡ e.printStackTrace();
¡¡¡¡
¡¡¡¡¡¡¡¡}
¡¡¡¡HttpServletResponse.sendRedirect()ÔòÊÇÍêÈ«µÄÌøת£¬ä¯ÀÀÆ÷½«»áµÃµ½Ìøת µÄµØÖ·£¬²¢ÖØз¢ËÍÇëÇóÁ´½Ó¡£ÕâÑù£¬´Óä¯ÀÀÆ÷µÄµØÖ·À¸ÖпÉÒÔ¿´µ½ÌøתºóµÄÁ´½ÓµØÖ·¡£Æäд·¨ÈçÏ£º
¡¡¡¡¡¡¡¡response.sendRedirect("display.jsp");
¡¡¡¡Á½ÕßÏà¶ÔÀ´ËµRequestDispatcher.forward()·½·¨¸ü¼Ó¸ßЧ£¬µ±Ëü¿ÉÒÔÂú×ãÐèҪʱ£¬¾¡Á¿Ê¹ÓÃRequest Dispatcher.forward()·½·¨£¬²¢ÇÒ£¬ÕâÑùÒ²ÓÐÖúÓÚÒþ²Øʵ¼ÊµÄÁ´½Ó¡£
Ïà¹ØÎĵµ£º
½ñÌìÓÖÓöµ½ÂÒÂëÎÊÌâ,¿ÉÕæ·³.ΪʲôTOMCAT¾Í²»ÄÜ×Ô¶¯ÅжÏÏîÄ¿µÄ±àÂë,¶øÒ»¶¨ÒªÏîÄ¿×ñÑTOMCATµÄ±àÂë.
˵˵½â¾ö·½·¨°É:
ÔÚTOMCATµÄSERVER.XMLÅäÖÃÎļþÖеÄconnectorÖÐÌí¼ÓURIEncoding="UTF-8"ÊôÐÔ,Èç
<Connector port="88" maxHttpHeaderSize="8192" maxThreads="20" minSpareThreads="5" maxSpareThreads="10"
e ......
String url="http://www.baidu.com";
ActionForward gotourl = new ActionForward(url);
gotourl.setPath(url);
gotourl.setRedirect(true);
return gotourl;
1.RequestDispatcher.forward()
¡¡¡¡ ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´ ......
µÚ1¸öÉÏ´«×é¼þcommons-fileupload
=============commons-fileupload ================
common-fileupload×é¼þÊÇapacheµÄÒ»¸ö¿ªÔ´ÏîÄ¿Ö®Ò»£¬¿ÉÒÔ´Óhttp://jakarta.apache.org/commons/fileupload/ÏÂÔØ¡£¸Ã×é¼þ¼òµ¥Ò×Ó㬿ÉʵÏÖÒ»´ÎÉÏ´«Ò»¸ö»ò¶à¸öÎļþ£¬²¢¿ÉÏÞÖÆÎļþ´óС¡£
-ÏÂÔغó½âѹzip°ü£¬½«commons-fileupload-1.1. ......
Ò»¡¢JSP¼ò½é
JSP (Java Server Pages)ÊÇ·þÎñÆ÷¶ËµÄ½Å±¾ÓïÑÔ£¬ÊÇÒ»ÖÖÔÚHTMLÒ³ÃæÖмÓÈëJavaÓïÑÔ¶øÉú³É¶¯Ì¬Ò³ÃæµÄ¼¼Êõ£º¼ÓÈëÁËеıêÇ©£¨<%£¬%>£¬…£©¡£
JSPÊÇÒÔJavaºÍServletΪ»ù´¡¿ª·¢¶ø³ÉµÄ¶¯Ì¬ÍøÒ³Éú³É¼¼Êõ£¬ËüµÄµ×²ãʵÏÖÊÇJava Servlet¡£
JSPÒ³ÃæÓÉHTML´úÂëºÍǶÈëÆäÖеÄJava´úÂëËù×é³É¡£·þÎñÆ÷ÔÚÒ³Ãæ±»¿Í» ......