www.pudn.com > Jsp-Blog.rar > LogServlet.java, change:2010-05-23,size:1055b


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.LogDao; 
 
public class LogServlet extends HttpServlet { 
 
	protected void doPost(HttpServletRequest request, 
			HttpServletResponse response) { 
		String username = (String) request.getSession() 
				.getAttribute("username"); 
		String logtitle = request.getParameter("logtitle"); 
		String logcontent = request.getParameter("logcontent"); 
		LogDao log = new LogDao(); 
		int num = log.logInsert(logtitle, logcontent, username); 
		if (num == 1) { 
			request.setAttribute("logmsg", "日志已保存!"); 
		} else { 
			request.setAttribute("logmsg", "日志保存失败!"); 
		} 
		try { 
			request.getRequestDispatcher("log.jsp").forward(request, response); 
		} catch (ServletException e) { 
 
			e.printStackTrace(); 
		} catch (IOException e) { 
 
			e.printStackTrace(); 
		} 
	} 
 
}