2023年12月17日发(作者:under是上面还是下面)
String sql = "select * from user order by id desc";conn = n();try {st = Statement();rs = eQuery(sql);while(()){user = new User();il(ing("email"));rname(ing("username"));swd(ing("passwd"));(("sex"));(("id"));(user);}} catch (SQLException e) {// TODO Auto-generated catch tackTrace();}finally{ll(conn, st, rs);}return list;}public User getUserById(int id){User user = null;Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;String sql ="select * from user where id=?";conn =n();try {ps = eStatement(sql);(1, id);rs = eQuery();while(()){
user = new User();il(ing("email"));rname(ing("username"));swd(ing("passwd"));(("sex"));(("id"));}} catch (SQLException e) {// TODO Auto-generated catch tackTrace();}finally{ll(conn, ps, rs);}return user;}<%@ page language="java" import=".*" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="/jstl/core_rt" %><%String path = textPath();String basePath = eme()+"://"+verName()+":"+verPort()+path+"/";%>
My JSP '' starting page
package t;import ption;import riter;import ;import tException;import rvlet;import rvletRequest;import rvletResponse;import o;import ;public class UserMessageServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {tentType("text/html;charset=UTF-8");String flag = ameter("flag");if("1".equals(flag)){getAllUsers(request,response);
}if("2".equals(flag)){getAllUsersMessage(request,response);}if("3".equals(flag)){getAllUsersMessageById(request,response);}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request,response);}public void getAllUsers(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {List list = tance().getUsers();ribute("list", list);uestDispatcher("/").forward(request, response);return;}public void getAllUsersMessage(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String id = ameter("id");User user = tance().getUserById(nt(id));ribute("user", user);uestDispatcher("/").forward(request, response);return;}public void getAllUsersMessageById(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String id = ameter("id");
// TODO Auto-generated catch tackTrace();}finally{ll(conn, st, rs);}return list;}public User getUserById(int id){User user = null;Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;String sql ="select * from user where id=?";conn =n();try {ps = eStatement(sql);(1, id);rs = eQuery();while(()){user = new User();il(ing("email"));rname(ing("username"));swd(ing("passwd"));(("sex"));(("id"));}} catch (SQLException e) {// TODO Auto-generated catch tackTrace();}finally{ll(conn, ps, rs);}return user;}
package t;import ption;import riter;import ;import tException;import rvlet;import rvletRequest;import rvletResponse;import o;import ;public class UserManagerServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {UserDao dao = new UserDao();List list = User();ribute("list", list);uestDispatcher("/").forward(request, response);return;}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}
<%@ page language="java" import=".*" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="/jsp/jstl/core"%><%String path = textPath();String basePath = eme()+"://"+verName()+":"+verPort()+path+"/";%>
My JSP '' starting page
ajax和dwr实现新闻的局部刷新:package ;import tException;import tion;import edStatement;import Set;import eption;import ist;import ;import ;import ;public class NewsDao {//private NewsDao(){
//}//private static NewsDao newsdao=null;//public static NewsDao getInstance(){// if(newsdao==null){// newsdao=new NewsDao();// }// return newsdao;//}public List getNews(int type,int startRow,int size){List list = new ArrayList();News news = null;Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;String sql = "select * from news where type=? order by id desc limit ?,?";conn = n();try {ps = eStatement(sql);(1,type );(2, startRow);(3, size);rs = eQuery();while(()){news = new News();time(e("addtime"));hor(ing("author"));tent(ing("content"));(("id"));el(("isdel"));le(ing("title"));e(("type"));(news);}} catch (SQLException e) {
--><%-- --%>
财经 军事
体育 娱乐