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

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±


Ïà¹ØÎĵµ£º

jsp servletÖкº×ÖÂÒÂëµÄ½â¾ö°ì·¨

 package servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloBeijing extends HttpServlet{
//public void init(ServletConfig config) throws ServletException{
// super.init(config);
//}
public void service(HttpServletRequest request,HttpServlet ......

JSP filter¹ýÂËÆ÷µÄ¹¦ÄܼòÒª½éÉÜ

filter¹¦ÄÜ.ËüʹÓû§¿ÉÒԸıäÒ»¸ö requestºÍÐÞ¸ÄÒ»¸öresponse. Filter ²»ÊÇÒ»¸öservlet,Ëü²»ÄܲúÉúÒ»¸öresponse,ËüÄܹ»ÔÚÒ»¸örequestµ½´ïservlet֮ǰԤ´¦Àírequest,Ò²¿ÉÒÔÔÚÀ뿪 servletʱ´¦Àíresponse.»»ÖÖ˵·¨,filterÆäʵÊÇÒ»¸ö¡±servlet chaining¡±(servlet Á´). Ò»¸öfilter °üÀ¨:
1. ÔÚservlet±»µ÷ÓÃ֮ǰ½Ø»ñ; ......

½â¾öAJAX(JSP)ÖÐÎÄÂÒÂë»òÌØÊâ·ûºÅ£¨&£©µÄ´«µÝÎÊÌâ

½â¾öAJAX(JSP)ÖÐÎÄÂÒÂë»òÌØÊâ·ûºÅ£¨&£©µÄ´«µÝÎÊÌâ----> ±¾ÈËÔ­´´£¨244796562@qq.com£©
************************js******************************
...
...
var s = encodeURIComponent("ÖÐÎÄ&English&@#$%!");
xmlReq.send("test", "txt=" + s, callback, callerror);//ͨ¹ýXMLHTTPRequest·¢ËÍ×Ö·ûÊý¾ ......

jsp ÂÒÂëÎÊÌâ

a.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageEncoding£½"GB2312"%%26gt;%26lt;form action£½"b.jsp"%26gt; name£º%26lt;input type£½text name£½name%26gt; %26lt;input type£½submit%26gt;%26lt;/form%26gt;
b.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageE ......

jspÔËÐÐʱ¾­³£Óöµ½µÄ¼¸¸öÎÊÌâ

1¡¢ÈçºÎÏÔʾĿ¼ÁÐ±í£º
ÎÒÃÇÔÚ±¾»ú²âÊÔ³ÌÐòʱ£¬Ò»°ã¶¼Ï°¹ßÔÚä¯ÀÀÆ÷ÖоÍÄܱéÀúµ½Ä³¸öĿ¼Ï¶¼ÓÐÄÄЩÎļþ£¬Õâ¾ÍÐèÒªweb·þÎñÆ÷Ö§³ÖĿ¼ÁÐ±í£º
´ò¿ªÎļþconf/web.xml£¬ÕÒµ½ÒÔÏ´úÂ룺
<param-name>listings</param-name>
<param-value>false</param-value>
½«ÆäÖеÄfalse¸Ä³Étrue
2¡¢ÅäÖÃerror-p ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ