User user=getModel(User.class); user.set("id", UUID.randomUUID().toString()); user.save();二、登陸時須要從前臺得到用戶名密碼而後去數據庫查詢是否存在
String name=getPara("user.name"); String password=getPara("user.password"); List<User> l=User.dao.find("select * from user where name='" +name+"' and password='"+password+"'");
三、保存和移除用戶信息到session中 html
//保存session getSession().setAttribute("username", name); //移除session getSession().removeAttribute("username");四、前臺使用jstl來判斷顯示不一樣的內容
<c:if test="${sessionScope.username!=null}"> <a href='/user/userInfo.jsp'>歡迎 ${sessionScope.username}</a> <a href='/user/logout'>註銷</a> </c:if> <c:if test="${sessionScope.username==null}"> <a href='/user/login.jsp'>登陸</a> <a href='/user/register.jsp'>註冊</a> </c:if>
jstl只有if沒有else,因此用了兩個if。分支多的時候能夠用下面的標籤
java
<c:choose> <c:when test="${condition1}"> condition1爲true </c:when> <c:when test="${ condition2}"> condition2爲true </c:when> <c:otherwise> condition1和condition2都爲false </c:otherwise> </c:choose>
五、servlet api
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/ 數據庫