📄 insertaction.java
字号:
package struts.action;import java.io.*;import java.sql.*;import javabean.*;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.sql.DataSource;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.upload.FormFile;import struts.form.InsertForm;public class InsertAction extends Action { //根据相应的条件进行处理 public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { InsertForm insertForm = (InsertForm) form; ConnectionPool pool=null; pool=ConnectionPool.getInstance(); Connection con=null; try { con=pool.getConnection(); } catch(SQLException e){} DBaseLT DBase=new DBaseLT(con); PubDate date=new PubDate(); ISOChange isoChange=new ISOChange(); HttpSession session=request.getSession(); String uuid=(String)session.getAttribute("uid"); if(uuid==null||uuid.length()==0) { return (mapping.findForward("login")); } FormFile file=insertForm.getFile(); String fname="no"; String dir=servlet.getServletContext().getRealPath("/image"); if(file!=null) { if(file.getFileSize()>0) { double i = 100 * Math.random(); fname=uuid+i+file.getFileName(); InputStream streamIn=file.getInputStream(); String path=dir+"/"+fname; IOStream iostream=new IOStream(); if(!iostream.IOHandle(path,streamIn)) { fname="no"; } } } if(insertForm.getYemian().equals("zhuti")) { if(((String)session.getAttribute("token")).equals(insertForm.getToken())) { resetToken(request); int code=DBase.getMaxcode()+1; String pubdate=date.getPubdate(); String title=insertForm.getTitle(); Stringtokenizer stringtoken=new Stringtokenizer(); String message=insertForm.getMessage(); message=stringtoken.getMessage(message); int huifu=0; int liulan=0; String photo=insertForm.getFace1()+insertForm.getFace2()+insertForm.getFace3()+".gif"; String quanxuan=(String)session.getAttribute("grant"); String insert="insert into luntan1 values("+code+",'"+uuid+"','"+title+"','"+message+"','"+pubdate+"',"+huifu+","+liulan+",'"+photo+"','"+fname+"',"+huifu+",'"+quanxuan+"')"; DBase.Insert(insert); String token=String.valueOf(Integer.parseInt(insertForm.getToken())+1); session.setAttribute("token",token); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showtitle")); } else { String token="1"; session.setAttribute("token",token); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showtitle")); } } if(insertForm.getYemian().equals("huifu")) { if(((String)session.getAttribute("token")).equals(insertForm.getToken())) { String pubdate=date.getPubdate(); String message=insertForm.getMessage(); Stringtokenizer stringtoken=new Stringtokenizer(); message=stringtoken.getMessage(message); String photo=insertForm.getFace1()+insertForm.getFace2()+insertForm.getFace3()+".gif"; int code=Integer.parseInt(insertForm.getCode()); int id=DBase.getMaxid(code)+1; String quanxuan=(String)session.getAttribute("grant"); String insert="insert into luntan2 values("+code+","+id+",'"+uuid+"','"+message+"','"+pubdate+"','"+photo+"','"+fname+"','"+quanxuan+"')"; DBase.Insert(insert); String str="update luntan1 set huifu=huifu+1 where code="+code; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); String token=String.valueOf(Integer.parseInt(insertForm.getToken())+1); session.setAttribute("token",token); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } else { String token="1"; session.setAttribute("token",token); int code=Integer.parseInt(insertForm.getCode()); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } } if(insertForm.getYemian().equals("edit")) { String pubdate=date.getPubdate(); String message=isoChange.Change(insertForm.getMessage()); int code=Integer.parseInt(insertForm.getCode()); int id=Integer.parseInt(insertForm.getId()); String str="update luntan2 set message='"+message+"<font color=#CCCCCC><p>edit by "+pubdate+"</font>'"+" where code="+code+" and id="+id; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } if(insertForm.getYemian().equals("delete")) { String pubdate=date.getPubdate(); int code=Integer.parseInt(insertForm.getCode()); int id=Integer.parseInt(insertForm.getId()); String query="select upload from luntan2 where code="+code+" and id="+id; String path=DBase.Query(query); if(!path.equals("no")) { File f=new File(dir,path); f.delete(); String updatepath="update luntan2 set upload='no' where code="+code+" and id="+id; DBase.Updatehuifu(updatepath); } String str="update luntan2 set message='"+"<font color=#CCCCCC><p>此贴已经删除<p>delete by "+pubdate+"</font>'"+" where code="+code+" and id="+id; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } if(insertForm.getYemian().equals("delete1")) { int code=Integer.parseInt(insertForm.getCode()); String query="select upload from luntan1 where code="+code; String path=DBase.Query(query); if(!path.equals("no")) { File f=new File(dir,path); f.delete(); } String str="delete from luntan1 where code="+code; DBase.Updatehuifu(str); String str1="delete from luntan2 where code="+code; DBase.Updatehuifu(str1); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showtitle")); } if(insertForm.getYemian().equals("edit1")) { String pubdate=date.getPubdate(); String message=isoChange.Change(insertForm.getMessage()); int code=Integer.parseInt(insertForm.getCode()); String str="update luntan1 set message='"+message+"<font color=#CCCCCC><p>edit by "+pubdate+"</font>'"+" where code="+code; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } if(insertForm.getYemian().equals("zhiding")) { int code=Integer.parseInt(insertForm.getCode()); String str="update luntan1 set grant1=2 where code="+code; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } if(insertForm.getYemian().equals("jing")) { int code=Integer.parseInt(insertForm.getCode()); String str="update luntan1 set grant1=1 where code="+code; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); try { if(con!=null) con.close(); }catch(SQLException e){} return (mapping.findForward("showhuifu")); } if(insertForm.getYemian().equals("annouce")) { int code=Integer.parseInt(insertForm.getCode()); String str="update luntan1 set grant1=3 where code="+code; DBase.Updatehuifu(str); String flag="ok"; request.setAttribute("flag",flag); request.setAttribute("code",String.valueOf(code)); return (mapping.findForward("showhuifu")); } return (mapping.findForward("logon")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -