1.登录
判断账号密码是否正确
<%
//设置编码
request.setCharacterEncoding("utf-8");
//获取参数
String username = request.getParameter("username");
String password = request.getParameter("password");
//封装
Users u = new Users(username,password);
//实例化
IUsersBiz iub = new UsersBizImpl();
Users users = iub.queryUsers(u);
if(users!=null){
session.setAttribute("users", users);
out.println("<script>alert('登录成功');location.href = 'index.jsp'</script>");
}else{
out.println("<script>alert('登录失败');location.href = 'index.jsp'</script>");
}
%>
2.显示所有资料
<%
//实例化分类
IThemesBiz itb = new ThemesBizImpl();
INewsBiz inb = new NewsBizImpl();
List<Themes> listThemes = itb.queryThemesAll();
/* System.out.println(listThemes.size()); */
List<News> listNews = null ;
//设置编码
request.setCharacterEncoding("utf-8");
//获取
int tid = 0;
String id = request.getParameter("tid");
if(null!=id){
tid = Integer.parseInt(id);
}
/* System.out.println(id); */
for(Themes t:listThemes){
/* ystem.out.println(t.getTid()); */
listNews = inb.queryNewsAll(t.getTid());
/* System.out.println(listNews); */
}
//实例化资料
request.setAttribute("listThemes", listThemes);
request.setAttribute("listNews", listNews);
request.getRequestDispatcher("index.jsp").forward(request, response);
%>
3.搜索功能
<%
//设置编码
request.setCharacterEncoding("utf-8");
//获取参数
String tname = request.getParameter("tname");
String ntitle = request.getParameter("ntitle");
String nauthor = request.getParameter("nauthor");
//实例化
INewsBiz inb = new NewsBizImpl();
List<News> listnews = inb.queryNewsAll(tname, ntitle, nauthor);
for(News n:listnews){
System.out.println(n);
}
session.setAttribute("listnews", listnews);
response.sendRedirect("index.jsp");
/* request.setAttribute("listnews", listnews);
request.getRequestDispatcher("index.jsp").forward(request, response); */
%>