JFinal使用笔记3-注册和登录功能开发记录

1、用户表的ID设置为字符串型,非空,在保存的时候需要给ID赋值。
User user=getModel(User.class);
user.set("id", UUID.randomUUID().toString());
user.save();
2、登录时需要从前台获得用户名密码然后去数据库查询是否存在
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+"'");

3、保存和移除用户信息到session中

//保存session
getSession().setAttribute("username", name);
//移除session
getSession().removeAttribute("username");
4、前台使用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。分支多的时候可以用下面的标签

<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>

5、servlet api
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/ 

转载于:https://my.oschina.net/u/173975/blog/113069

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值