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ÖеÄÌøת£º
(1). forward()·½·¨
ʹÓõ½javax.servlet.RequestDispatcherÀà
RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
/*forwardº ......
1¡¢·Ö±ð°²×°Èý¸ö»·¾³£¬²¢ÉèÖò»Í¬¶Ë¿Ú
PHP:80
JSP:8080
ASP:8081
2¡¢ÉèÖÃ/Apache2/conf/httpd.conf
È¥µôÒÔÏÂÈýÐÐÇ°µÄ×¢ÊÍ£º
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
¼ÓÈëÒÔϼ¸ÐУº ......
²úÉú״̬ÏìÓ¦Âë
100¡«199£º±íʾ·þÎñ¶Ë³É¹¦½ÓÊÕÇëÇ󣬵«ÒªÇó¿Í»§¶Ë¼ÌÐøÌá½»ÏÂÒ»´ÎÇëÇó²ÅÄÜÍê³ÉÈ«²¿´¦Àí¹ý³Ì¡£
200¡«299£º±íʾ·þÎñ¶ËÒѾ³É¹¦½ÓÊÕÇëÇ󣬲¢Íê³ÉÁËÈ«²¿´¦Àí¹ý³Ì¡£
300¡«399£º±íʾ¿Í»§¶ËÇëÇóµÄ×ÊÔ´ÒѾÒƵ½Á˱ðµÄλÖ㬲¢Ïò¿Í»§¶ËÌṩһ¸öеĵØÖ·£¬Ò»°ãÕâ¸öеØÖ·ÓÉHTTPÏìÓ¦ÏûϢͷµÄLocation×Ö¶ÎÖ¸¶¨¡£
400¡ ......
ÎҵĻ·¾³:
--------
1. java±àÒëÆ÷:eclipse 3.0.2
2. web·þÎñÆ÷: tomcat 4.1.24
3. C±àÒëÆ÷: VC6.0
4. ²Ù×÷ϵͳ: win2k
5. javaÔ´ÎļþĿ¼: d:\study\src
6. java±àÒëºóµÄclassÎļþĿ¼: d:\study\bin
7. tomcatĿ¼: d:\tomcat41
1.±àдjavaÎļþ:
//Util.java
package com.jni;
public class Util
{
& ......