0
我知道有這個問題的許多問題,但我不能確定我的..
我有,我定義一個對象類
從servlet的傳遞對象的jsp(返回null)
public class UserBean{
private String string1;
private String string1;
public String getString1(){
return String1;
}
public String getString2(){
return String2;
}
然後在我的Servlet我有:
//Create my Object1 and some other code...
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// some code...
HttpSession session = request.getSession(true);
request.setAttribute("PassingObj", Object1);
RequestDispatcher disp = getServletContext().getRequestDispatcher("/mypage.jsp");
disp.forward(request, response);
在我的jsp
則:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% ArrayList<UserBean> cis = (ArrayList) session.getAttribute("PassingObj"); %>
<c:forEach var="item" items="${cis}">
<c:out value="${cis.getString1}" />
</c:forEach>
然後我得到空..
我的對象有數組裏面...我測試打印在servlet內的控制檯相同的東西,它工作正常!謝謝..!
你說過「第一個問題,你正在設置請求屬性,並從會話中訪問它,當然你不會得到它。」我沒有得到它...你能expalin我plz? 至於我使用更明智的名字的名字。我只是把這些名字放在這裏... – yaylitzis
@yaylitzis。那麼,如果你在'request'中設置屬性,你只能從'request'中得到它的權利?不是來自'session'。他們都是不同的範圍。 –
是的它是有道理的.. – yaylitzis