Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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()Ö±½ÓʵÏÖÖض¨Î»¡£
¡¡¡¡×¢Ò⣺
¡¡¡¡ (1) ʹÓÃresponse.sendRedirectʱ£¬Ç°Ãæ²»ÄÜÓÐHTMLÊä³ö
¡¡¡¡Õâ²¢²»ÊǾø¶ÔµÄ£¬²»ÄÜÓÐHTMLÊä³öÆäʵÊÇÖ¸²»ÄÜÓÐHTML±»Ë͵½ÁËä¯ÀÀÆ÷¡£ÊÂʵÉÏÏÖÔÚµÄserver¶¼ÓÐcache»úÖÆ£¬Ò»°ãÔÚ8K£¨ÎÒÊÇ˵ JSP¡¡SERVER£©£¬Õâ¾ÍÒâζ×Å£¬³ý·ÇÄã¹Ø±ÕÁËcache£¬»òÕßÄãʹÓÃÁËout.flush()Ç¿ÖÆˢУ¬ÄÇôÔÚʹÓÃsendRedirect֮ǰ£¬ÓÐÉÙÁ¿µÄHTMLÊä³öÒ²ÊÇÔÊÐíµÄ¡£
¡¡¡¡ (2) response.sendRedirectÖ®ºó£¬Ó¦¸Ã½ô¸úÒ»¾äreturn;
¡¡¡¡ÎÒÃÇÒѾ­ÖªµÀresponse.sendRedirectÊÇͨ¹ýä¯ÀÀÆ÷À´×öתÏòµÄ£¬ËùÒÔÖ»ÓÐÔÚÒ³Ãæ´¦ÀíÍê³Éºó£¬


Ïà¹ØÎĵµ£º

jspÖ®session

     session¾ÍÊÇÒ»¸öÈ«¾Ö±äÁ¿£¬ÊÇä¯ÀÀÆ÷Ïß³ÌÔÚ·þÎñÆ÷¶ËµÄ´úÀí¡£web·þÎñ³ÌÐòÖ»Òª´ò¿ª£¬session¾Í»á´æÔÚ£¬µ±ÄãµÚÒ»´Î·ÃÎÊʱ£¬session»á×Ô¶¯ÎªÄã·ÖÅäÒ»¸ösession ID£¬ËùÒÔsessionΪн¨Á¢µÄ£¬ËùÒÔsession.isNew()Ϊtrue¡£µ±ÄãË¢ÐÂÒ³Ãæʱ£¬Õâ¸ösession IDÒ»Ö±´æÔÚ(session.getId()²»±ä)£¬²»»áÏûʧ£¬ËùÒÔse ......

jsp Ö®Filter

(1) ÇëÇóÐÅÏ¢±àÂëת»¯µÄFilter
importjava.io.IOException;
importjava.util.Enumeration;
importjavax.servlet.Filter;
importjavax.servlet.FilterChain;
importjavax.servlet.FilterConfig;
importjavax.servlet.ServletException;
importjavax.servlet.ServletRequest;
importjavax.servlet.ServletResponse;
......

JSPʵÀýÒ»¡¢¹ºÎï³µ


֪ʶ׼±¸£º
JDBC·ÃÎÊÊý¾Ý¿âµÄ»ù±¾²½Öè
£¨1£©¡¢½«Êý¾Ý¿âµÄJDBCÇý¶¯¼ÓÔص½¹¤³ÌÀà¿âÖС£
£¨2£©¡¢¼ÓÔØJDBCÇý¶¯£¬²¢½«Æä×¢²áµ½DriverManagerÖС£ÏÂÃæÊÇһЩÖ÷Á÷Êý¾Ý¿âµÄJDBCÇý¶¯¼ÓÔØ×¢²áÂ룺
¢Ù¡¢oracleÊý¾Ý¿â
Class.forName(“oracle.jdbc.driver.OracleDriver”).newInstance();
¢Ú¡¢Sql Server 7.0/2000Êý¾ ......

ÈçºÎ½â¾ö jsp ÖÐurl´«ÖµµÄÖÐÎÄÂÒÂëÎÊÌâ

ÔÚjspÖУ¬Èç¹ûÔÚurlÖд«µÝÖÐÎÄʱ»á³öÏÖÂÒÂ룬ÔÚÍøÉϹØÓÚÕâÒ»ÎÊÌâµÄ½â¾ö·½·¨Î廨°ËÃÅ£¬µ«¶¼²»ÊǺÜ×àЧ£¡Æäʵ½â¾ö·½·¨·Ç³£¼òµ¥£º µÚÒ»²½£º±àÂ루ÒÔ´«µÝµÄ²ÎÊýΪstrΪÀý£© ÔÚ´«µÝÊý¾ÝÇ°½«str½øÐбàÂëJava.net.URLEncoder.encode(str) µÚ¶þ²½£º½âÂë ÔÚ»ñÈ¡Êý¾Ý¶Ë½«µÃµ½µÄÊý¾Ý½øÐнâÂë new String£¨str.getBytes("ISO8859_1")£© ......

jspÖÐWord´òÓ¡

ÔÚjspÖÐÒýÓÃresponse.setContentType("application/msword");£¬´ò¿ªµÄÒ³Ãæ¾ÍÊÇwordÑùʽ¡£
1¡¢ÊµÏÖwordºá´ò£º
<style>
@page
 {mso-page-border-surround-header:no;
 mso-page-border-surround-footer:no;}
@page Section1
 {size:841.9pt 595.3pt;//Ö½ÕŵĴóС
 mso-page-orientation:l ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ