jsp:forward±êÇ©ºÍresponse.sendRedirect()·½·¨µÄÇø±ð
ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔÀ´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼,·¢ËÍÒ»¸ö״̬Âë,¸æËßä¯ÀÀÆ÷ÖØÐÂÈ¥ÇëÇóÄǸöµØÖ·.ËùÒÔµØÖ·À¸ÏÔʾµÄÊÇеÄURL.Ëù
ÒÔredirectµÈÓÚ¿Í»§¶ËÏò·þÎñÆ÷¶Ë·¢³öÁ½´Îrequest£¬Í¬Ê±Ò²½ÓÊÜÁ½´Îresponse¡£
2.´ÓÊý¾Ý¹²ÏíÀ´Ëµ
forward:ת·¢Ò³ÃæºÍת·¢µ½µÄÒ³Ãæ¿ÉÒÔ¹²ÏírequestÀïÃæµÄÊý¾Ý.
redirect:²»Äܹ²ÏíÊý¾Ý.
redirect²»½ö¿ÉÒÔÖض¨Ïòµ½µ±Ç°Ó¦ÓóÌÐòµÄÆäËû×ÊÔ´,»¹¿ÉÒÔÖض¨Ïòµ½Í¬Ò»¸öÕ¾µãÉϵÄÆäËûÓ¦ÓóÌÐòÖеÄ×ÊÔ´,
ÉõÖÁÊÇʹÓþø¶ÔURLÖض¨Ïòµ½ÆäËûÕ¾µãµÄ×ÊÔ´.
forward,·½·¨Ö»ÄÜÔÚͬһ¸öWebÓ¦ÓóÌÐòÄÚµÄ×ÊÔ´Ö®¼äת·¢ÇëÇó.
forward ÊÇ·þÎñÆ÷ÄÚ²¿µÄÒ»ÖÖ²Ù×÷.
redirect ÊÇ·þÎñÆ÷֪ͨ¿Í»§¶Ë,Èÿͻ§¶ËÖØз¢ÆðÇëÇó.
ËùÒÔ,Äã¿ÉÒÔ˵ redirect ÊÇÒ»ÖÖ¼ä½ÓµÄÇëÇó, µ«ÊÇÄã²»ÄÜ˵"Ò»¸öÇëÇóÊÇÊôÓÚforward»¹ÊÇredirect "
3.´ÓÔËÓõط½À´Ëµ
forward:Ò»°ãÓÃÓÚÓû§µÇ½µÄʱºò,¸ù¾Ý½Çɫת·¢µ½ÏàÓ¦µÄÄ£¿é.
redirect:Ò»°ãÓÃÓÚÓû§×¢ÏúµÇ½ʱ·µ»ØÖ÷Ò³ÃæºÍÌøתµ½ÆäËüµÄÍøÕ¾µÈ.
4.´ÓЧÂÊÀ´Ëµ
forward:¸ß.
redirect:µÍ.
5.jsp Óï·¨
<jsp:forward page={"relativeurl" | "<%= expression %>"} />
»òÕßÕâÑùд£º
<jsp:forward page={"relativeurl" | "<%= expression %>"} >
<jsp:param name="parametername" value="{parametervalue | <%= expression %>}" />+
</jsp:forward>
6.Àý×Ó
<jsp:forward page="/servlet/login" />
<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
ÃèÊö
<jsp:forward>±êÇ©´ÓÒ»¸öjspÎļþÏòÁíÒ»¸öÎļþ´«µÝÒ»¸ö°üº¬Óû§ÇëÇóµÄrequest¶ÔÏó.<jsp:forward>±êÇ©ÒÔϵĴúÂ룬½«²»ÄÜÖ´ÐÐ.
ÄãÄܹ»ÏòÄ¿±êÎļþ´«ËͲÎÊýºÍÖµ£¬ÔÚÕâ¸öÀý×ÓÖÐÎÒÃÇ´«µÝµÄ²ÎÊýÃûΪusername,ֵΪscott,Èç¹ûÄãʹÓÃÁË<jsp:param>±êÇ©µÄ»°£¬Ä¿±êÎļþ±ØÐëÊÇÒ»¸ö¶¯Ì¬µÄÎļþ£¬Äܹ»´¦Àí²ÎÊý.
Èç¹ûÄãʹÓÃÁË·Ç»º³åÊä³öµÄ»°£¬ÄÇôʹÓÃ<jsp:forward>ʱ¾ÍҪСÐÄ¡£
Èç¹ûÔÚÄãʹÓÃ<jsp:forward>֮ǰ£¬jspÎļþÒѾÓÐÁËÊý¾Ý£¬ÄÇôÎļþÖ´Ðоͻá³ö´í.
ÊôÐÔ
Ïà¹ØÎĵµ£º
ÒòΪÊǸú×ÅÊÓƵѧϰµÄ£¬ÓкܶàÓõĶ«Î÷²»Ò»Ñù£¬µ«ÊÇ»¹ÊÇÂýÂýµÄÃþË÷³öÀ´À²£¡
1.Microsoft JDBC Driver µÄÏÂÔØ°²×°
Ö»ÒªÔÚÍøÉÏÕÒµ½×ÊÔ´Ò»²½²½À´¾Í¿ÉÒÔÁË¡£
2.ÅäÖû·¾³±äÁ¿
ÎÒÓõÄÊÇtomcat6.0Ê×ÏÈÅäµÄÊÇ
classpathºÍpath£¬ÕâЩ¶¼ÊÇÔÚÅäjdkµÄʱºò¾ÍÅä¹ýÁË£¬ËùÒԾͲ»Ïêϸ˵Ã÷ÁË£¬Ö»Òª½«libºÍbinÎļþ¼ÓÈëµ½Ïà¹Ø ......
µÚÒ»ÖÖ£º
¾ÍÊÇÖ±½Ó¸ø³öÏÂÔصĵØÖ·£¬ÕâÖÖ·½Ê½ºÜ²»ºÃ£¬ÒòΪ»á±©Â¶ÄãµÄµØÖ·£¬´øÀ´ºÜ¶à²»°²È«µÄÒòËØ£¬¿ÉÒÔ˵ÊÇǧÍò²»ÒªÓÃÕâÖÖ
µÚ¶þÖÖ£º
ÏÂÔØÒ³Ãæ
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<html>
<head>
<title>download</title>
</head>
< ......
index.jsp
<%@ page language="java" import="java.sql.*" import="java.lang.*" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
& ......
jspÖеÚÒ»¾ä£º
<%@ page language="java" import="java.sql.*,java.util.*," contentType="text/HTML;charset=gb2312" pageEncoding="gb2312"%>
htmlÖмÓÉÏ
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
ͨ³£ÕâÑù¾ÍûÓÐÎÊÌâÁË¡£ .
ÔÙÕߣº µ¼ÈëjsʱºòÉ ......
JSPÖеÄCOOKIE²Ù×÷
Cookie¸ÅÄî:
CookieµÄ¸ñʽʵ¼ÊÉÏÊÇÒ»¶Î´¿Îı¾ÐÅÏ¢, ÓÉ·þÎñÆ÷Ëæ×ÅÍøÒ³Ò»Æð·¢Ë͵½¿Í»§¶Ë, ²¢±£´æÔÚ¿Í»§¶ËÓ²ÅÌÖÐÖ¸¶¨µÄĿ¼µÄ. ´ó¼Ò¶¼´«ËµCookie»áÔì³ÉÑÏÖصݲȫÍþвʲôµÄ, Æäʵ²»ÊÇÕâô»ØÊÂÇé. ·þÎñÆ÷¶ÁÈ¡CookieµÄʱºò, Ö»Äܹ»¶ÁÈ¡µ½Õâ¸ö·þÎñ ......