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

JSPÒ³ÃæÌøתµÄÎåÖÖ·½·¨

1. RequestDispatcher.forward()
ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚ b.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ. µ«forward()ÎÞ·¨Öض¨ÏòÖÁÓÐframeµÄjspÎļþ,¿ÉÒÔÖض¨ÏòÖÁÓÐframeµÄhtmlÎļþ,ͬʱforward()ÎÞ·¨ÔÚºóÃæ´ø²ÎÊý´«µÝ,±ÈÈçservlet?name=frank,ÕâÑù²»ÐÐ,¿ÉÒÔ³ÌÐòÄÚͨ¹ýresponse.setAttribute("name",name)À´´«ÖÁÏÂÒ»¸öÒ³Ãæ¡£
Öض¨Ïòºóä¯ÀÀÆ÷µØÖ·À¸URL²»±ä¡£ Àý£ºÔÚservletÖнøÐÐÖض¨Ïò
public void doPost(HttpServletRequest request,HttpServletResponse response)   throws ServletException,IOException   {   ¡¡ response.setContentType("text/html; charset=gb2312");   ¡¡ ServletContext sc = getServletContext();   ¡¡ RequestDispatcher rd = null;   ¡¡ rd = sc.getRequestDispatcher("/index.jsp"); //¶¨ÏòµÄÒ³Ãæ   ¡¡ rd.forward(request, response);   }   
ͨ³£ÔÚservletÖÐʹÓ㬲»ÔÚjspÖÐʹÓá£
2. response.sendRedirect()
ÊÇÔÚÓû§µÄä¯ÀÀÆ÷¶Ë¹¤×÷,sendRedirect()¿ÉÒÔ´ø²ÎÊý´«µÝ,±ÈÈçservlet?name=frank´«ÖÁϸöÒ³Ãæ,ͬʱËü¿ÉÒÔÖض¨ÏòÖÁ²»Í¬µÄÖ÷»úÉÏ,sendRedirect()¿ÉÒÔÖض¨ÏòÓÐframe.µÄjspÎļþ.
Öض¨ÏòºóÔÚä¯ÀÀÆ÷µØÖ·À¸ÉÏ»á³öÏÖÖض¨ÏòÒ³ÃæµÄURL¡£Àý£ºÔÚservletÖÐÖض¨Ïò
public void doPost(HttpServletRequest request,HttpServletResponse response)   throws ServletException,IOException   {   ¡¡ response.setContentType("text/html; charset=gb2312");   ¡¡ response.sendRedirect("/index.jsp");   }  
ÓÉÓÚresponseÊÇjspÒ³ÃæÖеÄÒþº¬¶ÔÏ󣬹ÊÔÚjspÒ³ÃæÖпÉÒÔÓÃresponse.sendRedirect()Ö±½ÓʵÏÖÖض¨Î»¡£
×¢Ò⣺
¡ôʹÓÃresponse.sendRedirectʱ£¬Ç°Ãæ²»ÄÜÓÐHTMLÊä³ö£»
Õâ²¢²»ÊǾø¶ÔµÄ£¬²»ÄÜÓÐHTMLÊä³öÆäʵÊÇÖ¸²»ÄÜÓÐHTML±»Ë͵½ÁËä¯ÀÀÆ÷¡£ÊÂʵÉÏÏÖÔÚµÄserver¶¼ÓÐcache»úÖÆ£¬Ò»°ãÔÚ8K£¨ÎÒÊÇ˵ JSP¡¡SERVE


Ïà¹ØÎĵµ£º

ÔÚJSPÖÐÏÂÔØÎı¾Îĵµ

ͨ³££¬ÎÒÃÇÐèÒªÌṩһ¸öÎļþÏÂÔصÄʱºò£¬½öÐèÒªÒ»¸ö³¬Á´½Ó¾Í¿ÉÒÔ½â¾ö¡£
 
±ÈÈçexeÎļþ£¬Êó±ê×ó¼üµã»÷Á´½Ó¾Í»áÌáʾÄãÖ±½ÓÖ´Ðл¹ÊDZ£´æ£¬ÓÒ¼üÔò¿ÉÒÔÖ±½ÓÁí´æΪ¡£¡£¡£
 
µ«ÊÇÓÐÒ»²¿·ÖÎļþ£¬±ÈÈçtxtµÈ¿ÉÒÔÔÚä¯ÀÀÆ÷ÖÐÖ±½Ó´ò¿ªµÄÎļþ£¬ÄãÖ»ÄÜÓÃÊó±êÓÒ¼üµã»÷Á´½ÓÈ»ºóÁí´æΪµÄ·½Ê½È¥±£´æ¸ÃÎļþ£¬Èç¹ûÖ±½Óµã»÷×ó¼ü£¬¸Ã ......

JSPÓëSERVLETµÄ¹Øϵ

×ÛÊö£ºJava ServletÊÇJSP¼¼ÊõµÄ»ù´¡£¬¶øÇÒ´óÐ͵ÄWebÓ¦ÓóÌÐòµÄ¿ª·¢ÐèÒªJava ServletºÍJSPÅäºÏ²ÅÄÜÍê³É¡£ÏÖÔÚÐí¶àWeb·þÎñÆ÷¶¼Ö§³ÖServlet£¬¼´Ê¹²»Ö±½ÓÖ§³ÖServletµÄWeb·þÎñÆ÷£¬Ò²¿ÉÒÔͨ¹ý¸½¼þµÄÓ¦Ó÷þÎñÆ÷ºÍÄ£¿éÀ´Ö§³ÖServlet£¬ÕâµÃÒæÓÚJavaµÄ¿çƽ̨ÌØÐÔ¡£ÁíÍ⣬ÓÉÓÚServletÄÚ²¿ÒÔÏ̷߳½Ê½ÌṩÌṩ·þÎñ£¬²»±Ø¶ÔÓÚÿ¸öÇëÇó¶¼Æ ......

JSPµÄÅäÖÃ

¿ª·¢»·¾³ÅäÖÃ
¡¡¡¡
¡¡¡¡Ò»¡¢¿ª·¢»·¾³ÅäÖÃ
¡¡¡¡
¡¡¡¡µÚÒ»²½£ºÏÂÔØj2sdkºÍtomcat£ºµ½sun¹Ù·½Õ¾£¨http://java.sun.com/j2se/1.5.0/download.jsp£©ÏÂÔØj2sdk£¬×¢ÒâÏÂÔذ汾ΪWindows Offline InstallationµÄSDK£¬Í¬Ê±×îºÃÏÂÔØJ2SE 1.5.0 Documentation£¬È»ºóµ½tomcat¹Ù·½Õ¾µã£¨http://jakarta.apache.org/site/downloads/do ......

jspÀïµÄ·¾¶ÎÊÌâ

     ×î½üÔÚѧjsp£¬ÔÚÕâÀïÁôÏÂÓ¡¼Ç£¬ÒÔÃâÍü¼Ç¡£
 
     ÔÚ˵jspÀïµÄ·¾¶ÎÊÌâÇ°ÏÈ˵ÏÂä¯ÀÀÆ÷½âÎöÍøÒ³µÄÔ­Àí¡£¼ÙÉèÄãÓÐÈçϵÄjspÒ³Ã棬ÎļþÃûΪtext.jsp£¬ÎļþλÓÚmyjsp¹¤³ÌϵÄwebrootÀï¡£
  <%@ page language="java"  pageEncoding="gb2312" %>
  ......

JSP Á¬½Ósqlserver Êý¾Ý¿â

¼òµ¥µÄÁ¬½ÓÊý¾Ý¿âµÄ²âÊÔ´úÂë
<%@¡¡page¡¡import="java.lang.*,¡¡java.io.*,¡¡java.sql.*,¡¡java.util.*"¡¡contentType="text/html;charset=gb2312"¡¡%>
¡¡¡¡<html>
¡¡¡¡<body>
¡¡¡¡<%¡¡Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
¡¡¡¡¡¡String¡¡url="jdbc:m ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ