www.pudn.com > Jsp-Blog.rar > AddFavoriteLogServlet.java, change:2010-05-26,size:1187b


package myblog.servlet; 
 
import java.io.IOException; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import myblog.dao.AddFavoriteLogDao; 
 
public class AddFavoriteLogServlet extends HttpServlet { 
 
	public void doPost(HttpServletRequest request, HttpServletResponse response) { 
		String username = request.getSession().getAttribute("username") 
				.toString(); 
		String logid = request.getParameter("logid"); 
		AddFavoriteLogDao fav = new AddFavoriteLogDao(); 
		int num = fav.repeatFavoriteLog(logid); 
		if (num == 1) { 
			request.setAttribute("favmsg", "此文章您已经收藏了"); 
		} else { 
			int number = fav.addFavoriteLog(username, logid); 
			if (number == 1) { 
				request.setAttribute("favmsg", "收藏成功!!"); 
			} else { 
				request.setAttribute("favmsg", "收藏失败!!"); 
			} 
		} 
		try { 
			request.getRequestDispatcher("addFavouriteSucess.jsp").forward(request, response); 
		} catch (ServletException e) { 
			e.printStackTrace(); 
		} catch (IOException e) { 
			e.printStackTrace(); 
		} 
 
	} 
 
}