package org.itstar.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.itstar.bean.contextbean;
import org.itstar.bean.huifubean;
import org.itstar.bean.phonebean;
import org.itstar.dao.contextdao;
import org.itstar.dao.huifudao;
import org.itstar.dao.photodao;
import org.itstar.util.DBConnection;
public class heheservlet extends HttpServlet {
private String info = "";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
info = request.getParameter("info");
if (info.equals("deleteone")) {
this.deleteone(request, response);
}
if (info.equals("update")) {
this.update(request, response);
}
if (info.equals("userprintPhoto")) {
this.user_printPhoto(request, response);
}
if (info.equals("pinglun")) {
this.pinglun(request, response);
}
if(info.equals("insert")){
this.insert(request,response);
}
if(info.equals("deletetwo")){
this.delettwo(request, response);
}
if(info.equals("fuck")){
this.fuck(request, response);
}
if(info.equals("huifu")){
this.huifu(request, response);
}
if(info.equals("deletethree")){
this.deletethree(request, response);
}
}
private void deletethree(HttpServletRequest request,
HttpServletResponse response) throws ServletException,IOException{
huifudao huifu=new huifudao();
int id=Integer.parseInt(request.getParameter("id"));
int photoid=Integer.parseInt(request.getParameter("photoid"));
huifubean bean=new huifubean();
bean.setId(id);
huifu.deleteone(id);
request.getRequestDispatcher("/servlet/pinglunservlet?id="+photoid).forward(request, response);
}
private void delettwo(HttpServletRequest request,
HttpServletResponse response)throws ServletException,IOException {
contextdao context=new contextdao();
int id=Integer.parseInt(request.getParameter("id"));
int photoid=Integer.parseInt(request.getParameter("photoid"));
contextbean bean=new contextbean();
bean.setId(id);
context.delete(id);
request.getRequestDispatcher("/servlet/pinglunservlet?id="+photoid).forward(request, response);
}
//执行回复操作
private void insert(HttpServletRequest request, HttpServletResponse response) throws
ServletException ,IOException{
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
huifudao huihu=new huifudao();
int pinglunid=Integer.parseInt(request.getParameter("pinglunid"));
String huifu=request.getParameter("huifu");
String username=request.getParameter("username");
int photoid=Integer.parseInt(request.getParameter("photoid"));
Date date=new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String ordertime=format.format(date).toString();
huifubean bean=new huifubean();
bean.setPinglunid(pinglunid);
bean.setHuifu(huifu);
bean.setUsername(username);
bean.setPhotoid(photoid);
bean.setOrdertime(ordertime);
if(huihu.inser(bean)){
request.setAttribute("xujun1", bean);
request.getRequestDispatcher("/servlet/pinglunservlet?id="+photoid).forward(request, response);
}else{
out.print("<script language=javascript>alert('回复失败');history.go(-1);</script>");
}
}
private void huifu(HttpServletRequest request, HttpServletResponse response) throws
ServletException ,IOException{
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
huifudao huihu=new huifudao();
int pinglunid=Integer.parseInt(request.getParameter("pinglunid"));
String huifu=request.getParameter("huifu");
String username=request.getParameter("username");
int photoid=Integer.parseInt(request.getParameter("photoid"));
huifubean bean=new huifubean();
bean.setPinglunid(pinglunid);
bean.setHuifu(huifu);
bean.setUsername(username);
if(huihu.inser(bean)){
request.setAttribute("xujun1", bean);
request.getRequestDispatcher("/servlet/friendservlet?id="+photoid).forward(request, response);
}else{
out.print("<script language=javascript>alert('回复失败');history.go(-1);</script>");
}
}
private void fuck(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=gb2312");
contextdao dao = new contextdao();
contextbean bean = new contextbean();
String photo = request.getParameter("photoid");
int photoid=Integer.parseInt(photo);
System.out.println(photoid);
String context = request.getParameter("context");
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String ordertime = format.format(date).toString();
String username = request.getParameter("username");
bean.setPhotoid(photoid);
bean.setContext(context);
bean.setOrdertime(ordertime);
bean.setUsername(username);
if (dao.insert(bean)) {
request.setAttribute("xujun", bean);
request.getRequestDispatcher("/servlet/friendservlet?id="+photoid).forward(request, response);
} else {
out.print("<script language=javascript>alert('评论失败');history.back();</script>");
}
}
private void pinglun(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=gb2312");
contextdao dao = new contextdao();
contextbean bean = new contextbean();
String photo = request.getParameter("photoid");
int photoid=Integer.parseInt(photo);
System.out.println(photoid);
String context = request.getParameter("context");
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String ordertime = format.format(date).toString();
String username = request.getParameter("username");
bean.setPhotoid(photoid);
bean.setContext(context);
bean.setOrdertime(ordertime);
bean.setUsername(username);
if (dao.insert(bean)) {
request.setAttribute("xujun", bean);
request.getRequestDispatcher("/servlet/pinglunservlet?id="+photoid).forward(request, response);
} else {
out.print("<script language=javascript>alert('评论失败');history.back();</script>");
}
}
private void update(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html;charset=gb2312");
photodao photo = new photodao();
int id = Integer.parseInt(request.getParameter("id"));
String phoneaddress = request.getParameter("phoneaddress");
String phonesize = request.getParameter("phonesize");
String phototype = request.getParameter("phototype");
String photoDescription = request.getParameter("photoDescription");
String phonetime = request.getParameter("phonetime");
String PrintAddress = request.getParameter("PrintAddress");
int userid = Integer.parseInt(request.getParameter("userid"));
phonebean bean = new phonebean();
bean.setId(id);
bean.setPhoneaddress(phoneaddress);
bean.setPhonesize(phonesize);
bean.setPhototype(phototype);
bean.setPhotoDes