0
我需要將兩個數組轉發到一個jsp頁面來顯示它們。我已經成功地使用下面的代碼轉發單個陣列:如何使用sendRedirect從servlet發送多個數組到jsp
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String n = request.getParameter("name");
int k = Integer.parseInt(n);
int array[] = new int[3];
PrintWriter out = response.getWriter();
List<RecommendedItem> recommendations = new ArrayList<RecommendedItem>();
try {
recommendations = App.getRecommend(k);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int i = 0;
// out.println("we recommend");
for (RecommendedItem recommendation : recommendations) {
// out.println(recommendation.getItemID()+" "
// +recommendation.getValue());
array[i] = (int) recommendation.getItemID();
i++;
}
String param = Arrays.toString(array);
param = param.substring(1, param.length() - 1);// removing enclosing []
String encArray = URLEncoder.encode(param, "utf-8");
// Send encArray as parameter.
response.sendRedirect(("output.jsp?fib=" + encArray));
}
但現在我要轉發的(int)recommendation.getValue()
組成的output.jsp的第二陣列。可以使用response.sendRedirect()
完成嗎?