本期内容:
1、登录注册
2、菜单栏展示
3、权限登录
一、登录与注册
1、首先需要将界面样式与jar包导入
帮助包:
2、根据数据库写个用户实体类
3、写登录与注册方法(UserDao)
package lv.com.dao;
import java.util.List;
import com.lv.util.BaseDao;
import com.lv.util.PageBean;import lv.com.entity.RolePermission;
import lv.com.entity.User;public class UserDao extends BaseDao<User>{
// 登录
public User login(User user) throws Exception {
String sql="select * from t_easyui_user where name='"+user.getName()+"'and pwd='"+user.getPwd()+"'";
return super.executeQuery(sql, User.class, null).get(0);
}
// 注册
public void register(User user) throws Exception {
String sql="insert into t_easyui_user(name,pwd) values(?,?)";
super.executeUpdate(sql, user, new String[] {"name","pwd"});
}}
4、写子控制器UserAction
package lv.com.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lv.framework.ActionSupport;
import com.lv.framework.ModelDriver;
import lv.com.dao.UserDao;
import lv.com.entity.User;
public class UserAction extends ActionSupport implements ModelDriver<User>{
private User user=new User();
private UserDao ud=new UserDao();
@Override
public User getModel() {
// TODO Auto-generated method stub
return user;
}
public String login(HttpServletRequest req, HttpServletResponse resp) {
try {
User u = ud.login(user);
// 如果没有该对象,则跳到登录界面
if(u==null) {
return "toLogin";
}
// 存放数据
req.getSession().setAttribute("cuser", u);
} catch (Exception e) {
e.printStackTrace();
// 出现异常也跳到登录界面
return "toLogin";
}
// 登录成功跳到主界面
return "main";
}
public String register(HttpServletRequest req, HttpServletResponse resp) {
try {
ud.register(user);
// 提示
req.setAttribute("msg","用户名密码错误");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "toRegister";
}
// 注册成功跳转到登录界面
return "toLogin";
}
}
2、配置文件,也就是用于跳转界面
<action path="/user" type="lv.com.web.UserAction">
<forward name="main" path="/bg/mainTemp.jsp" redirect="false" />
<forward name="toLogin" path="/login.jsp" redirect="true" />
<forward name="toRegister" path="/register.jsp" redirect="false" />
</action>
展示:
二、后管树形菜单展示
1、根据数据库写菜单栏的实体类
2、写方法(PermissionDao)
package lv.com.dao;