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
Ïà¹ØÎĵµ£º
´ó¼Ò×ÜÊDz»Ï²»¶¿´µ½<%ºÍ%>ÔÚjspÒ³ÃæÉÏ£¬ÆäʵÎÒÃÇ¿ÉÒÔʹÓñȽÏÓÅÑŵÄxml·½Ê½À´±í´ï
1£¬Òþº¬µÄ×¢ÊÍ
JSPÓï·¨£º<%-- ÄÚÈÝ --%>
XMLÓï·¨£ºÎÞ
2£¬±äÁ¿»òº¯ÊýµÄÉùÃ÷
JSPÓï·¨:<%! declaration;[declaration;]+... %>
ÀýÈ磺
<%!
int i=0;int a,b,c;
Color red=new Color( ......
ʯ¼ÒׯÌáÉýÍøÕ¾ÐÔÄܵķ½Ê½Óкܶ࣬ÀýÈçÓÐЧµÄʹÓûº´æ£¬Éú³É¾²Ì¬Ò³ÃæµÈµÈ¡£½ñÌìҪ˵µÄ¾Í
ÊÇÉú³É¾²Ì¬Ò³ÃæµÄ·½Ê½¡£
ʲô½ÐÉú³É¾²Ì¬Ò³ÃæÄØ£¿ºÜ¼òµ¥£¬ÀýÈçÎÒÃÇÈç¹û·ÃÎÊÒ»¸öÁ´½Ó http://xyz.com/index.do£¬
ÄÇô·þÎñÆ÷¾Í»á½âÎöÕâ¸öÇëÇó£¬ÈÃÌض¨µÄAction È¥´¦Àí¡£ÕâÆäÖеÄȱµãÊÇÏÔ¶øÒ×¼ûµÄ£ºÈç¹û
·ÃÎʵÄÈË£¬ÄÇô¾Í»á¼ÓÖØÓ¦Ó÷ ......
²úÉúÑéÖ¤ÂëͼƬµÄÎļþimage.jsp
<%@ page contentType="image/jpeg" import="java.awt.*,
java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){//
¸ø¶¨·¶Î§»ñµÃËæ»úÑÕÉ«
Random random = new ......
ÓÃORACLE9i¡¢oracle8¡¢Óкܳ¤µÄÒ»¶Îʱ¼ä£¬ÎÒ°ÑÓÃÓÚJSPÖÐÐèҪעÒâµÄÎÊÌâÔÚÕâÀïд³öÀ´£¬½ö¹©´ó¼Ò²Î¿¼ÁË¡£
¡¡¡¡Ò»¡¢ÈçºÎÈ¥´¦ÀíClob¡¢BLOBµÄ´óÀàÐÍ
¡¡¡¡CLOB¿ÉÓÃÓÚ´æ·Å´óÎı¾Êý¾Ý,×î¶à¿É´æ´¢4GBÊý¾Ý,ÔÚÓ¦Óÿª·¢ÖбȽϳ£¼û.javaÌṩµÄsql.ClobÀàÓëÖ®¶ÔÓ¦.ËüÌṩÁ½¸ö·½·¨À´¶ÁÈ¡ClobµÄÊý¾Ý:
¡¡¡¡getCharacterStream() ·½·¨·µ»Ø° ......