Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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 6u12+Tomcat6.0+JSP¾­µäÅäÖÃ(Íêȫ׼ȷÎÞÎó£©

µÚÒ»²½£º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ÖеÄÌøת£º
(1). forward()·½·¨
    ʹÓõ½javax.servlet.RequestDispatcherÀà
    RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
    rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
    /*forwardº ......

Apache¡¢Tomcat¡¢IIS£¨PHP¡¢JSP¡¢ASP£©¹²´æʱµÄÉèÖÃ

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
¼ÓÈëÒÔϼ¸ÐУº ......

TomcatÔõô´¦ÀíJSPÒ³Ãæ

²úÉú״̬ÏìÓ¦Âë
100¡«199£º±íʾ·þÎñ¶Ë³É¹¦½ÓÊÕÇëÇ󣬵«ÒªÇó¿Í»§¶Ë¼ÌÐøÌá½»ÏÂÒ»´ÎÇëÇó²ÅÄÜÍê³ÉÈ«²¿´¦Àí¹ý³Ì¡£
200¡«299£º±íʾ·þÎñ¶ËÒѾ­³É¹¦½ÓÊÕÇëÇ󣬲¢Íê³ÉÁËÈ«²¿´¦Àí¹ý³Ì¡£
300¡«399£º±íʾ¿Í»§¶ËÇëÇóµÄ×ÊÔ´ÒѾ­ÒƵ½Á˱ðµÄλÖ㬲¢Ïò¿Í»§¶ËÌṩһ¸öеĵØÖ·£¬Ò»°ãÕâ¸öеØÖ·ÓÉHTTPÏìÓ¦ÏûϢͷµÄLocation×Ö¶ÎÖ¸¶¨¡£
400¡ ......

jspµ÷ÓÃjni·½·¨

ÎҵĻ·¾³:
--------
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
{
 & ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ