📄 forumpostaction.java
字号:
package com.laoer.bbscs.bbs.action;
import org.apache.struts.action.*;
import org.apache.struts.upload.*;
import javax.servlet.http.*;
import com.laoer.bbscs.bbs.actionform.*;
import com.laoer.bbscs.bbs.business.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import com.laoer.bbscs.servlet.*;
import com.laoer.bbscs.db.*;
import org.apache.struts.util.*;
import java.util.*;
import java.io.*;
import org.apache.log4j.*;
public class ForumPostAction
extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionErrors errors = new ActionErrors();
if (actionForm instanceof PostActionForm) {
PostActionForm form = (PostActionForm) actionForm;
UserSessionCheck myUserSessionCheck = new UserSessionCheck(form.getSid(),
httpServletRequest);
if (!myUserSessionCheck.checkSession(form.getBid())) {
errors.add("error.timeout", new ActionError("error.timeout"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
if (myUserSessionCheck.isGuest()) {
errors.add("noguest", new ActionError("error.user.noguest"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
httpServletRequest.setAttribute("myUserSessionCheck", myUserSessionCheck);
httpServletRequest.setAttribute("sid", form.getSid());
httpServletRequest.setAttribute("bid", form.getBid());
if (form.getAction().equals("add")) {
UserInfo myUserInfo = myUserSessionCheck.getUser().getUserInfo();
BoardsInfo theBoards = myUserSessionCheck.getTheBoards();
String IP = httpServletRequest.getRemoteAddr();
int artSize = 0;
try {
artSize = form.getDetail().getBytes(Sys.SYSINFO.CHARSET).length;
}
catch (Exception e) {
System.out.println(e);
}
int mypower = 0; //气力值
mypower = myUserInfo.getPower();
if (mypower <= 0 &&
! (myUserSessionCheck.isSuperAdmin() ||
myUserSessionCheck.isBMaster() ||
myUserSessionCheck.isMainMaster() ||
myUserSessionCheck.isAssiMaster() ||
myUserSessionCheck.isHideMaster())) {
errors.add("nopower", new ActionError("error.post.nopower"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
String sign_detail = "";
if (form.getSign().equals("0")) {
sign_detail = "";
}
else {
sign_detail = Util.addSlashes(myUserInfo.getSing_Detail(Integer.
parseInt(form.getSign())));
}
ForumInfo aForumInfo = new ForumInfo();
long postTime = Util.getaLongTime();
long aID = TableID.nextID(4);
aForumInfo.setID(aID);
aForumInfo.setID1(0);
aForumInfo.setID2(aID);
aForumInfo.setBoardID(theBoards.getID());
aForumInfo.setBoardName(theBoards.getBoardsName());
aForumInfo.setFace(Integer.parseInt(form.getBq()));
aForumInfo.setTitle(form.getTitle());
aForumInfo.setDetail(form.getDetail());
aForumInfo.setSign(sign_detail);
aForumInfo.setArtSize(artSize);
aForumInfo.setEmail_Inform(Integer.parseInt(form.getEmail_inform()));
aForumInfo.setMsg_Inform(Integer.parseInt(form.getMsg_inform()));
aForumInfo.setPostTime(postTime);
aForumInfo.setLastTime(postTime);
aForumInfo.setIPAddress(IP);
aForumInfo.setIsNew(1);
aForumInfo.setNickName(myUserInfo.getNickName());
FormFile file = form.getForm_data();
boolean isHavePic = false;
if (file != null && file.getFileName() != null &&
file.getFileName().length() > 0) {
if (Util.isAllowFile("pic", file.getFileName())) {
String imgFileName = "img_" + aID + "_" + postTime +
Util.getFileExt(file.getFileName());
aForumInfo.setHavePic(1);
aForumInfo.setPicName(imgFileName);
isHavePic = true;
}
else {
errors.add("upnotice", new ActionError("post.upnotice"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
}
Forum aForum = ForumFactory.getInstance();
aForum.setUserInfo(myUserInfo);
aForum.setForumInfo(aForumInfo);
aForum.setUserSessionCheck(myUserSessionCheck);
int result = 0;
if (isHavePic) {
result = aForum.createPost(null, "new", file);
}
else {
result = aForum.createPost(null, "new");
}
if (result != Sys.RESULT_RIGHT) {
errors.add("posterror", new ActionError("error.posterror"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
User myUser = myUserSessionCheck.getUser();
myUser.setUserInfo(aForum.getUserInfo());
UserSession myUserSession = ServerSession.getSession(form.getSid(),
httpServletRequest);
myUserSession.setAttribute("user", myUser);
ServerSession.upSession(myUserSession);
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("succeed.jrzc",
Sys.getURL() + "boardSaveAction.do?sid=" + form.getSid() +
"&action=show"));
return actionMapping.findForward("forwards");
}
}
return actionMapping.findForward("error");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -