後台獲取
值類型 request.getSession().setAttribute("username", user.getUserName());
對象類型 request.getSession().setAttribute("user", user);
前台應用
值: <br> 用struts標簽: <s:property value="#session.username" /> <br> 用EL表達式:${session.username} <br> 用java代碼:<%=session.getAttribute("username")%> <br> 對象 <br> 用struts標簽: <s:property value="#session.user.userName" /> <br> 用EL表達式:${session.user.password} <br> 用java代碼:<%=session.getAttribute("user")%> <br>
前台上傳表單頁面
<s:form action="login1"> 用戶<s:textfield name="user.userName" type="text"/> <s:textfield name="user.password" key="pass" /> <s:textfield name="password" key="pass" /> <s:submit key="login" /> </s:form>
後台獲取
對象
private User user; public User getUser() { return user; } public void setUser(User user) { this.user = user; }
值
//與前台頁面name="password" 一致 public void setPassword(String password) { this.password = password; }