jsp Ìøת·½Ê½
ʹÓÃJSP´óÔ¼ÓÐÏÂÁÐÈýÖÖÌøת·½Ê½£º
1. response.sendRedirect();
2. response.setHeader("Location","");
3. £¼jsp:forward page="" /£¾
¾¹ýÊÔÑéµÃµ½ÏÂÃæµÄһЩ¹æÔò£º
Ò». response.sendRedirect()
´ËÓï¾äÇ°²»ÔÊÐíÓÐout.flush()£¬Èç¹ûÓÐout.flush()£¬»áÓÐÒì³££º
java.lang.IllegalStateException: Can't sendRedirect() after data has committed to the client.
at com.caucho.server.connection.AbstractHttpResponse.sendRedirect(AbstractHttpResponse.java:558)
...
Ìøתºóä¯ÀÀÆ÷µØÖ·À¸±ä»¯
Èç¹ûÒªÌøµ½²»Í¬Ö÷»úÏ£¬Ìøתºó£¬´ËÓï¾äºóÃæµÄÓï¾ä»á¼ÌÐøÖ´ÐУ¬ÈçͬпªÁËỊ̈߳¬µ«ÊǶÔresponseµÄ²Ù×÷ÒѾÎÞÒâÒåÁË£»
Èç¹ûÒªÌøµ½ÏàͬÖ÷»úÏ£¬´ËÓï¾äºóÃæµÄÓï¾äÖ´ÐÐÍê³Éºó²Å»áÌøת£»
¶þ. response.setHeader("Location","")
´ËÓï¾äÇ°²»ÔÊÐíÓÐout.flush()£¬Èç¹ûÓÐout.flush()£¬Ò³Ãæ²»»áÌøת¡£
Ìøתºóä¯ÀÀÆ÷µØÖ·À¸±ä»¯
´ËÓï¾äºóÃæµÄÓï¾äÖ´ÐÐÍê³Éºó²Å»áÌøת
Èý. £¼jsp:forward page="" /£¾
´ËÓï¾äÇ°²»ÔÊÐíÓÐout.flush()£¬Èç¹ûÓУ¬»áÓÐÒì³££º
java.lang.IllegalStateException: forward() not allowed after buffer has committed.
at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:134)
at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:101)
at com.caucho.jsp.PageContextImpl.forward(PageContextImpl.java:836)
...
Ìøתºóä¯ÀÀÆ÷µØÖ·À¸²»±ä£¬µ«ÊÇÖ»ÄÜÌøµ½µ±Ç°Ö÷»úÏÂ
´ËÓï¾äºóÃæµÄÓï¾äÖ´ÐÐÍê³Éºó²Å»áÌøת
Ïà¹ØÎĵµ£º
µÚÒ»²½£ºJDKÓëTomcatµÈµÄÏÂÔØÓëÅäÖÃ
×îеÄJDKΪ6.0£¨jdk-6u12-windows-i586-p.exe£©£¬tomcatΪ6.0(apache-tomcat-6.0.18.exe)
¿ª·¢»·¾³£º
JDK: jdk-6u12-windows-i586-p.exe
ÏÂÔصØÖ·:http://java.sun.com/javase/downloads/index.jsp
Tomcat:apache-tomcat-6.0.18.exe
ÏÂÔصØÖ·:http://tomcat.a ......
JSPµÄÔËÐÐÄÚÄ»
¾³£ÓÐÅóÓÑÎÊÆð£¬JSPºÍServletÖ®¼äÓÐʲôÇø±ð£¬Á½ÕßÖ®¼äÓÖÓÐʲôÁªÏµ£¿ÆäʵServlet¼¼ÊõµÄ³öÏÖʱ¼äºÜÔ磬Êǵ±Ê±ÎªÁËJavaµÄ·þÎñÆ÷¶ËÓ¦Óöø¿ª·¢µÄ¡£´ó¼Ò¶¼ÖªµÀAppletÊÇÓ¦ÓÃС³ÌÐò£¬Servlet¾ÍÊÇ·þÎñÆ÷¶ËС³ÌÐòÁË¡£µ«ÔÚMicrosoft¹«Ë¾µÄASP¼¼Êõ³öÏÖºó£¬Ê¹Óà Servlet½øÐÐÏìÓ¦Êä³öʱһÐÐÐеÄÊä³öÓï¾ä¾ÍÏԵ÷dz£±¿×¾£ ......
jsp request session
µÈ¶ÔÏó
Ïê½â
תÕß×¢£º´ËÎÄ×ܽá½ÏΪÏêϸ£¬ÖµµÃ²Î¿¼¡£µ«²¿·ÖÄÚÈݾ¹ýÕûÀí£¬ÒÔÏÂÊÇÕýÎÄ¡£
1.request
¶ÔÏó
ÕâÁ½¸ö¶ÔÏóÊÇASPËùÌṩµÄÄÚÖöÔÏóÖÐ×î³£ÓõÄÁ½¸ö¡£ÔÚä¯ÀÀÆ÷£¨»òÆäËûÓû§´úÀí£©ºÍWeb·þÎñÆ÷Ö®¼ä£¬ÇëÇóÓëÏìÓ¦Öз¢ÉúµÄÐÅÏ¢½»Á÷¿ÉÒÔͨ¹ýASPÖеÄÁ½¸öÄÚÖöÔÏóÀ´½øÐÐ ......
²úÉú״̬ÏìÓ¦Âë
100¡«199£º±íʾ·þÎñ¶Ë³É¹¦½ÓÊÕÇëÇ󣬵«ÒªÇó¿Í»§¶Ë¼ÌÐøÌá½»ÏÂÒ»´ÎÇëÇó²ÅÄÜÍê³ÉÈ«²¿´¦Àí¹ý³Ì¡£
200¡«299£º±íʾ·þÎñ¶ËÒѾ³É¹¦½ÓÊÕÇëÇ󣬲¢Íê³ÉÁËÈ«²¿´¦Àí¹ý³Ì¡£
300¡«399£º±íʾ¿Í»§¶ËÇëÇóµÄ×ÊÔ´ÒѾÒƵ½Á˱ðµÄλÖ㬲¢Ïò¿Í»§¶ËÌṩһ¸öеĵØÖ·£¬Ò»°ãÕâ¸öеØÖ·ÓÉHTTPÏìÓ¦ÏûϢͷµÄLocation×Ö¶ÎÖ¸¶¨¡£
400¡ ......
Ò³ÃæµÄÊäÈëºÍÊä³öÉæ¼°µ½ÁËRequestºÍResponse,ÓÉÓÚËûÃǺÍJspÖеÄÏàËÆ,
ÏÂÃæÎÒÃǽøÐÐÏêϸµÄ½â¶Á£º
JSPÖУº
ÔÚ¶¯Ì¬ÍøÒ³¿ª·¢ÖУ¬HTML±íµ¥ÊÇÓëÓû§½»»¥ÐÅÏ¢µÄÖ÷ÒªÊֶΡ£
ʹÓÃJSP´¦Àí±íµ¥ÇëÇóʱ£¬Ò»°ã×ñÑÕâÑùÒ»ÖÖģʽ£¬Ê×ÏÈ£¬Óû§Í¨¹ý±íµ¥¿Ø¼þÊäÈë²¢Ìá½»ÐÅÏ¢;½Ó×Å£¬JSPÒ³Ãæ»ñµÃ±íµ¥Êý ......