www.pudn.com > restrant.zip > FeelbackMsgServlet.java, change:2014-01-25,size:1816b


package com.alex.restrantol.servlet; 
 
import java.io.IOException; 
import java.text.SimpleDateFormat; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import com.alex.restrantol.dao.FeelbackMsgDao; 
import com.alex.restrantol.entity.FeelbackMsgEntity; 
import com.alex.restrantol.entity.PageEntity; 
import com.alex.restrantol.entity.UserEntity; 
 
public class FeelbackMsgServlet extends HttpServlet { 
	protected void service(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException { 
		req.setCharacterEncoding("utf-8"); 
		res.setCharacterEncoding("utf-8"); 
		String type = req.getParameter("type"); 
		int currentPage = 1; 
		if ("findMsg".equals(type)) { 
			String p = req.getParameter("page"); 
			if(p!=null){ 
				currentPage = Integer.parseInt(p); 
			} 
			PageEntity pageEntity = new FeelbackMsgDao().getPageEntity(currentPage); 
			req.setAttribute("pageEntity", pageEntity); 
			req.getRequestDispatcher("feedback.jsp").forward(req, res); 
		}else if("sendMsg".equals(type)){ 
			UserEntity user = (UserEntity) req.getSession().getAttribute("user"); 
			String sendnote = req.getParameter("note"); 
			if(user != null && sendnote != null && sendnote.trim().length() >0){ 
				FeelbackMsgEntity msg=new FeelbackMsgEntity(); 
				msg.setUserId(user.getId()); 
				msg.setUserName(user.getName()); 
				msg.setSendNote(sendnote); 
				msg.setSendTime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(System.currentTimeMillis()).toString()); 
				new FeelbackMsgDao().addFeelbackMsg(msg); 
				res.sendRedirect("FeelbackMsgServlet?type=findMsg"); 
			}else{ 
				res.sendRedirect("FeelbackMsgServlet?type=findMsg"); 
			} 
		} 
	} 
}