JSPä¸æ交表åçåæ¶é¡µé¢è·³è½¬æ¯éè¿servletæ§å¶çã
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);
}
温馨提示:内容为网友见解,仅供参考