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

jspÒ³ÃæÌøת·½·¨´óÈ«

JSPÖеÄÌøת£º
(1). forward()·½·¨
    ʹÓõ½javax.servlet.RequestDispatcherÀà
    RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
    rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
    /*forwardº¯ÊýÒѾ­°ÑÔ­Ò³ÃæµÄrequest,response¶ÔÏó´«ÈëеÄÒ³Ã棬Òò´ËÕâоÉÒ³ÃæÓµÓÐÏàͬµÄrequest,response¶ÔÏó¡£request.getparameter("var")¾Í¿ÉÒԵõ½ÏàÓ¦µÄÖµ.*/
    /*forward()ÊÇÖ±½ÓÔÚserver×öµÄ£¬ä¯ÀÀÆ÷²¢²»ÖªµÀ£¬Ò²²»ºÍä¯ÀÀÆ÷´ò½»µÀ£¬ä¯ÀÀÆ÷µÄµØÖ·²»±ä»¯¡£*/
    ¼´£º
    getServletContext().getRequestDispatcher("url").forward(requestVar,responseVar);
    ·þÎñÆ÷¶ËServlet½øÐÐתÏòµÄ4ÖÖ·½·¨£º
    1.ServletContextµÄgetRequestDispatcher()    
    2.ServletContextµÄgetNamedDispatcher()   
    3.ServletRequestµÄgetRequestDispatcher()   
    4.ServletResponseµÄsendredirect()½øÐÐתÏò¡£
    forward·½·¨£¬ÒòΪÕâЩÕâÑù±È½Ï¸ßЧ¡£Ö»ÓÐÔÚforward·½·¨²»ÄÜʹÓÃʱ£¬ÔÙʹÓÃservletresponseµÄsendredirect()·½·¨¡£
(2).response.sendRedirect(url);  
    ÆäʵÊÇÏòä¯ÀÀÆ÷·¢ËÍÒ»¸öÌØÊâµÄHeader£¬È»ºóÓÉä¯ÀÀÆ÷À´×öתÏò£¬×ªµ½Ö¸¶¨µÄÒ³Ã棬ËùÒÔÓÃsendRedirectʱ£¬ä¯ÀÀÆ÷µÄµØÖ·À¸ÉÏ¿ÉÒÔ¿´µ½µØÖ·µÄ±ä»¯¡£ÐÂÒ³Ãæ²»ÄÜ´¦Àí¾ÉÒ³ÃæµÄpagecontext(request,response,...)¶ÔÏó.
    ÔÚresponse.sendRedirectÖ®ºó£¬Ó¦¸Ã½ô¸úÒ»¾äreturn;
(3).HTMLÓïÑÔµÄ×Ô¶¯Ìøת
    <html>
    <head>
        <meta http-equiv="refresh" content="0;url="http://www.baidu.com">
        0Êǵȴýʱ¼ä£¬Èç¹ûÉèÖÃΪ5±íʾµÈ´ý5sºó¿ªÊ¼Ìøת
    </head>
    …………
(4).JavaScriptÌøת
A:    <script languate="javascript">
   &


Ïà¹ØÎĵµ£º

×éÆ´jsp·½·¨

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> ......

¿´V512ÊÓƵJsp/Servletѧϰ±Ê¼Ç

//ѧϰ±Ê¼Ç, ¿ÉÄÜÓÐЩµØ·½Àí½âÓÐÎó, »á±í´ï²»Çå³þ
        v512_servlet+jsp
01 ÔÚÐÞ¸ÄÍêCookieºó,Ò»¶¨Òª¼ÓÉÏresponse.addCookie(c);
   CookieÖÐÖ»Äܱ£´æ×Öĸ»òÊý×ÖÐÅÏ¢;
02 req.getSession()Óëreq.getSession(boolean create)
   ÎÞ²ÎÊýµÄ == ÓвÎÊýµÄ²ÎÊýÎ ......

¹ØÓÚjspÖеÄcookieС³ÌÐò

<body>
 <%
   Cookie[] cookies = request.getCookies() ;
   Cookie cookie = null ;
   if(cookies!=null){
     cookie = cookies[0] ;
     out.print("ÉϴηÃÎʵÄipÊÇ£º " + request.getRemoteAddr() +"<br>") ;&n ......

JSPÌøתµÄ¼¸ÖÖ·½Ê½|Struts¶¯Ì¬Ìøת

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