Á˽âJSPÖÐrequestÊôÐÔµÄÓ÷¨
±¾ÎĽéÉÜJSPÖÐrequestÊôÐÔµÄÓ÷¨£¬ÒÔ¼°request.getParameter() ºÍrequest.getAttribute() Çø±ð¡£
Ò»¡¢request.getParameter() ºÍrequest.getAttribute() Çø±ð
1.request.getParameter()È¡µÃÊÇͨ¹ýÈÝÆ÷µÄʵÏÖÀ´È¡µÃͨ¹ýÀàËÆpost£¬getµÈ·½Ê½´«ÈëµÄÊý¾Ý£¬request.setAttribute()ºÍgetAttribute()Ö»ÊÇÔÚwebÈÝÆ÷ÄÚ²¿Á÷ת£¬½ö½öÊÇÇëÇó´¦Àí½×¶Î¡£
2.request.getParameter()·½·¨´«µÝµÄÊý¾Ý£¬»á´ÓWeb¿Í»§¶Ë´«µ½Web·þÎñÆ÷¶Ë£¬´ú±íHTTPÇëÇóÊý¾Ý¡£request.getParameter()·½·¨·µ»ØStringÀàÐ͵ÄÊý¾Ý¡£
request.setAttribute()ºÍgetAttribute()·½·¨´«µÝµÄÊý¾ÝÖ»»á´æÔÚÓÚWebÈÝÆ÷ÄÚ²¿»¹ÓÐÒ»µã¾ÍÊÇ£¬HttpServletRequestÀàÓÐsetAttribute()·½·¨£¬¶øûÓÐsetParameter()·½·¨¡£ÄÃÒ»¸öÀý×ÓÀ´ËµÒ»Ï°ɣ¬¼ÙÈçÁ½¸öWEBÒ³Ãæ¼äΪÁ´½Ó¹Øϵʱ£¬¾ÍÊÇ˵Ҫ´Ó1.JSPÁ´½Óµ½2.JSPʱ£¬±»Á´½ÓµÄÊÇ2.JSP¿ÉÒÔͨ¹ýgetParameter()·½·¨À´»ñµÃÇëÇó²ÎÊý.
¼ÙÈç1.JSPÀïÓÐ
<form name="form1" method="post" action="2.jsp"> ÇëÊäÈëÓû§ÐÕÃû£º<input type="text" name="username"> <input type="submit" name="Submit" value="Ìá½»"> form>
µÄ»°ÔÚ2.JSPÖÐͨ¹ýrequest.getParameter("username")·½·¨À´»ñµÃÇëÇó²ÎÊýusername:
< % String username=request.getParameter("username"); %>µ«ÊÇÈç¹ûÁ½¸öWEB¼äΪת·¢¹Øϵʱ£¬×ª·¢Ä¿µÄWEB¿ÉÒÔÓÃgetAttribute()·½·¨À´ºÍת·¢Ô´WEB¹²Ïírequest·¶Î§ÄÚµÄÊý¾Ý£¬Ò²»¹ÊÇ˵һ¸öÀý×Ó°É¡£ÓÐ1.JSPºÍ2.JSP
1.JSPÏ£ÍûÏò2.JSP´«µÝµ±Ç°µÄÓû§Ãû×Ö£¬ÈçºÎ´«µÝÕâÒ»Êý¾ÝÄØ£¿ÏÈÔÚ1.JSPÖе÷ÓÃÈçÏÂsetAttribute()·½·¨£º
<% String username=request.getParameter("username"); request.setAttribute("username"£¬username); %> <jsp:forward page="2.jsp" /> ÔÚ2.jspÖÐͨ¹ýgetAttribute()·½·¨»ñµÃÓû§Ãû×Ö: <% String username=(String)request.getAttribute("username"); %>
¶þ¡¢request.getAttribute()Óërequest.setAttribute()
request.getAttribute("nameOfObj")¿ÉµÃµ½JSPÒ³ÃæÒ»±íµ¥ÖпؼþµÄValue¡£Æäʵ±íµ¥¿Ø¼þÖеÄObjectµÄ nameÓëvalueÊÇ´æ·ÅÔÚÒ»¸ö¹þÏ£±íÖеģ¬ËùÒÔÔÚÕâÀï¸ø³öObjectµÄname»áµ½¹þÏ£±íÖÐÕÒ³ö¶ÔÓ¦ËüµÄvalue¡£
¶ø²»Í¬Ò³Ãæ¼ä´«ÖµÊ¹ÓÃrequest.setAttribute(positi
Ïà¹ØÎĵµ£º
JSP +Tomcat
Êý¾Ý¿â·ÃÎÊ
×÷ÕߣºÁõÖ¾Ô¶
ÔÚÒ»°ãµÄ
Web
ÏîÄ¿¿ª·¢ÖУ¬¶ÔÊý¾Ý¿âµÄ·ÃÎÊÊDZز»¿ÉÉٵģ¬±¾ÎÄÖ÷Òª½éÉÜÁ½ÖÖÔÚ
ʹÓÃ
Tomcat
×÷Ϊ
Web
·þÎñµÄ
JSP
¿ª·¢ÖзÃÎÊÊý¾Ý¿âµÄ·½·¨£¬Ï£ÍûÄܶԸսӴ¥
JSP
¿ª·¢µÄÅóÓÑÓÐËù°ïÖú¡£
ÓÃ
¹ý
.NET
ƽ̨µÄÅóÓÑÓ¦¸ÃÖªµÀ£¬ÏîÄ¿ÖÐÐèÒª·ÃÎÊÊý¾Ý¿âʱ£ ......
<%
//header.jsp
out.println("Protocol: " + request.getProtocol() + "<br>");
out.println("Scheme: " + request.getScheme() + "<br>");
out.println("Server Name: " + request.getServerName() + "<br>" );
out.println(&quo ......
СµÜ×î½ü¹«Ë¾×öÒ»¸ö±à¼Æ÷£¬×îºóÑ¡ÔñÓÃappletС³ÌÐòǶÈëjsp ÖÐ
Ï൱ÓÚÒ»¸ö¿ØÖÆ£¬×ܽá·ÖÏíһϣº
Ö÷ÒªÅöµ½ÒÔÏÂÎÊÌ⣺
1£¬´«²ÎÊýÎÊÌ⣺
applet-->jsp:
<applet code="rubikApp.class" archive="rubik.jar" width="300" height="300">
<param name="beta" ......
Ò»¡¢JSP×Ô¶¨Òå±êÇ©¼ò½é
±êÇ©ÊÇÒ»ÖÖXMLÔªËØ£¬Í¨¹ý±êÇ©¿ÉÒÔʹJSPÍøÒ³±äµÃ¼ò½à²¢ÇÒÒ×ÓÚά»¤£¬»¹¿ÉÒÔ·½±ãµØʵÏÖͬһ¸öJSPÎļþÖ§³Ö¶àÖÖÓïÑÔ°æ±¾¡£ÓÉÓÚ±êÇ©ÊÇXMLÔªËØ£¬ËùÒÔËüµÄÃû³ÆºÍÊôÐÔ¶¼ÊÇ´óСдÃô¸ÐµÄ
±ê×¼JSP±êÇ©ÊÇÓÃÀ´µ÷ÓÃJavaBean×é¼þµÄ²Ù×÷£¬´¦Àí¶¨ÏòÇëÇóÒÔ¼ò»¯JSPÒ³Ã濪·¢Óëά»¤¡£JSP¼¼ÊõÌṩÁËÒ»ÖÖ·â×°ÆäËü¶¯Ì¬ÀàÐÍ ......
ÎÒÃǶ¼ÖªµÀÔÚjspÖÐincludeÓÐÁ½ÖÖÐÎʽ,·Ö±ðÊÇ
¡¡¡¡< %@ include file=” ”%>
¡¡¡¡< jsp:include page=” ” flush=”true”/>
¡¡¡¡Ç°ÕßÊÇÖ¸ÁîÔªËØ¡¢ºóÕßÊÇÐÐΪԪËØ¡£¾ßÌåËüÃǽ«Ôںδ¦Óã¿ÈçºÎÓü°ËüÃÇÓÐʲôÇø±ð£¿ÕâÓ¦¸ÃÊǺܶàÈË¿´µ½Ëü¶¼»áÏëµ½µÄÎÊÌâ¡£ÏÂÃæÒ»ÆðÀ´¿´¿´°É ......