我從servlet調用了一個JSP,displayItems.jsp
,DataPortal.java
。首先,我試圖做到這一點使用RequestDispatcher
這樣,從servlet調用jsp
String url = "/displayItems.jsp";
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(toDo);
dispatcher.forward(req, res);
以及...的控制也去JSP頁面,但它打印的JSP文件的全部內容(包括標籤的所有內容),而不是顯示爲網頁。接下來我試圖通過使用response.sendRedirect(url);
來實現這一點,這次它給了我一個空白頁面。我在這裏做錯了什麼?該JSP是這樣的,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.js" type="text/javascript"></script>
</head>
<body>
<div>i am in display category</div>
</body>
</html>
任何幫助表示讚賞。
噢好吧。這意味着我不應該嘗試使用sendRedirect。但我仍然不明白爲什麼前鋒不適合我。 – sherry 2011-04-04 15:48:41