JSPÓëServletµÄÌøת¼°µÃµ½Â·¾¶·½·¨ÕûÀí
½ñÌìÕûÀíÏîÄ¿µÄÁ÷³Ì£¬ÔÚJSPºÍServletÖ®¼äÌøÀ´ÌøÈ¥£¬Ôø¾Ò»¶Îʱ¼ä£¬ÎÒ¶¼ÊÇ°ÑServlet·¾¶¶¨ÒåΪ¡°/SomeServlet¡±£¬Ò²¼´¶¨ÒåΪ¸ùĿ¼£¬ÒòΪ¼æÈÝÐԱȽϺ㬵«ÊÇÓÃÁËMyEclipseÖ®ºó£¬Ð½¨µÄServletĬÈÏ·¾¶ÊÇ¡°/servlet/SomeServlet¡±£¬ÕâÑùд±ãÓÚ¹ÜÀí£¬ÁíÍâ¾ÍÊǸüÊʺϵ¥¶ÀΪServletÉèÖÃFilter£¨¹ØÓÚFilterµÄÉèÖÿÉÒԲο¼ÕâƪÎÄÕ£©¡£¶øÎÒµÄJSPÎļþÄ¿Ç°ÊÇ·ÅÔÚÏîÄ¿µÄ¸ùĿ¼£¬Ò²¼´ÐγÉÏÂͼÕâÑùµÄ·¾¶½á¹¹£º /ProjectRoot/
|--servlet/
| |--Servlet1
| |--Servlet2
|
|--myJsp1.jsp
|--myJsp2.jsp ÆäÖÐServletÌøתÓÐÁ½ÖÖ·½Ê½£º
1¡¢sendRedirect()·½Ê½ response.sendRedirect(String targetUrl);
2¡¢RequestDispather·½Ê½ RequestDispatcher requestDispatcher = request.getRequestDispatcher(String targetUrl);
requestDispatcher.forward(request, response); µÚÒ»ÖÖ·½Ê½ÊǸøÓû§ä¯ÀÀÆ÷·¢ËÍ֪ͨ£¬È»ºóÓÉä¯ÀÀÆ÷ÔÙ¸ø·þÎñÆ÷·¢ËÍÌøתÇëÇó£¬ËùÒԱȽÏÀàËÆÓû§×Ô¼ºÈ¥µãURLµÄÌøת£¬ÕâÖÖ·½Ê½Èç¹ûÐèÒª´«²Î¸øÌøתҳÃ棬ÐèҪʹÓÃSession»òÕßʹÓÃGET·½Ê½½«²ÎÊýÏÔʽµÄдÔÚtargetUrlÀÈ磺ooxx.jsp?id=1£©£¬¶øÇҴ󲿷ÖÇé¿öÏÂÓÉÓÚGET·½·¨µÄ¾ÖÏÞÐÔ£¬ÕâÖÖÌøת·½Ê½Ö»ÄÜ´ø½ÏΪ¼òµ¥µÄ²ÎÊý¡£ ¶øµÚ¶þÖÖ·½Ê½ÓеãÀàËÆC#ÖеÄServer.Transfer()·½·¨£¬¼´·þÎñÆ÷¶ËÌøת£¬´ÓÏÖÏóÉÏ¿´¾ÍÊÇÓû§µÄä¯ÀÀÆ÷ÄÚÈÝ·¢ÉúÁ˱仯£¬µ«ÊÇä¯ÀÀÆ÷µÄµØÖ·À¸²»±ä»¹ÊÇÀϵØÖ·¡£ÕâÖÖ·½Ê½ÓÉ·þÎñÆ÷Ö±½Ó¿ØÖÆrequest¼°responseµÄ×ßÏò¼°²ÎÊý£¬´ÓÃüÁîÐеIJÎÊýÉϾͿÉÒÔ¿´³öÕâÒ»µã¡£ÕâÑù·½±ã³ÌÐòÔ±¿ØÖƲÎÊýµÄ´«µÝ£¬¼¸ºõ¿ÉÒÔ´«µÝÈκÎÀàÐ͵IJÎÊý£¬Ö»Òª¼òµ¥µÄʹÓÃsetAttribute()·½·¨¼´¿É£º request.setAttribute(String attriName, Object attriValue); µ«ÊÇÒ²¾ÍÊÇÒòΪËüÊÇ·þÎñÆ÷¶ËÌøת£¬ËùÒÔÓû§ä¯ÀÀÆ÷µÄµØÖ·À¸ÊDz»·¢Éú±ä»¯µÄ¡£ÄÇô£¬Èç¹ûÏîĿ·¾¶½á¹¹ÈçÉÏͼËùʾµÄÇé¿ö£¬ÄÇô£º
1¡¢´ÓJSPÌøתÏòServletʱ
Ö»Òª¼òµ¥µÄʹÓÃÏà¶Ô·¾¶¡°serlvet/SomeServlet¡±¼´¿É¡£ 2¡¢´ÓServletÌøתÏòÁíÒ»¸öServletʱ
ÒòΪServlet¶¼ÔÚÏàͬ·¾¶Ï£¬ËùÒÔ¿ÉÒÔÖ±½ÓдÏà¶Ô·¾¶£¬Èç¡°./SomeServlet¡±»òÖ±½Ó¡°SomeServlet¡±¡£ 3¡¢´ÓServletÌøתÏòJSPʱ
ÒòΪServlet·¾¶Îª¡°servlet/SomeServlet¡±£¬ËùÒÔÈç¹ûҪʹÓÃRequestDispather·½Ê½Ìøת£¬JSPÒ³ÃæÔÚ½Ó²ÎÊýʱ£¬»á½«µØÖ·À¸µÄµØÖ·×÷Ϊµ±Ç°Ä¿Â¼Ñ°ÕÒ×Ô¼ºÐèÒªµÄ·½·¨¡¢JavaScript¡¢CSSµÈ¡£ËùÒÔ¾³£ÓÐÅóÓÑÓöµ½JavaScript±
Ïà¹ØÎĵµ£º
½â¾ö°ì·¨£º
µÚÒ»£º
1:ÔÚjspÒ³Ãæ¼ÓÈ룺
<%@ page contentType="text/html; charset=gb2312" %>
2:ÔÚservletÀïÃæ:
public void doGet(HttpServletRequest request, HttpServletResponse &nbs ......
ÒòΪ³õѧ£¬ËùÒÔ£¬ÔÚ½¨Á¢StatementʱʹÓÃĬÈϲÎÊý¡£µ¼ÖÂÔÚʹÓÃÖ´ÐÐrs.last()ʱ£¬²úÉú“java.sql.SQLException£º¶Ôֻת·¢½á¹û¼¯µÄÎÞЧ²Ù×÷£ºlast”µÄÒì³£¡£
×îºóÔÚ½¨Á¢Statementʱ¼ÓÈëÏà¹Ø²ÎÊý£¬¾Í¿ÉÒÔ½â¾öÁË¡£
²Ù×÷²éѯ½á¹û¼¯µÄ¹ý³ÌÖгöÏÖÒì³£
³öÏÖÒì³£µÄÓï¾ä: rs.last();
Òì³£µÄÏêϸÐÅ ......
ÐèÒª¼ÇסµÄ֪ʶµã£º
1 ÇëÇóÓ¦´ðģʽ£¬¿Í»§¶Ë·¢ËÍÇëÇ󣬷þÎñÆ÷½øÐÐÏìÓ¦
2 JSPÎļþÊÇÔÚ·þÎñÆ÷¶ËÖ´ÐеÄ
3 ·µ»Ø¸ø¿Í»§¶ËµÄ½á¹ûÊÇJSPÎļþÖ´ÐеĽá¹û£¬²»°üº¬ÈκÎJSPÓï·¨
4 ÄÚ²¿¶ÔÏóÊÇÔÚ°ÑJSPÎļþת»»ÎªJava´úÂëµÄʱºòÉú³ÉµÄ
5 Ö´ÐеIJ¢²»ÊÇJSPÎļþ±¾Éí£¬¶øÊÇJSPת»»³ÉµÄJavaÀàµÄ¶ÔÏóµÄ·½·¨£¬ËùÒÔÓÐʱºòÐÞ¸ÄJSPÎļþ² ......
×öÁËÒ»¸öСģ¿é ÐèÒª ÔÚjspÒ³ÃæÉÏ°´ÕÕExcel±¨±í¸ñʽÏÔʾ±íÍ· ËäÈ»²»¸´ÔÓ µ«ÊǵÚÒ»´Î×ö Áô¸ö¼ÍÄî
ÕâЩ¶«Î÷¸ßÊÖµ±È»ÊDz»ÐèÒªÁË µ«ÊǶÔÓÚû×ö¹ýµÄ ¿ÉÄÜ»á¸øÄãÒ»µãµãÊÕ»ñ
ҪעÒâµÄÊÇ ±íÍ·µÄrowspanºÍcolspan ºáÊúҪƥÅä ²»È»ÏÂÃæÔÙÌí¼Ó ±í¸ñ»áÂÒ ÓÐɶ²»Çå³þµÄ »¶ÓÁôÑÔ
<%@ page language="java" pageEncoding="UT ......