📄 noteaction.java
字号:
package com.laoer.bbscs.bbs.action;
import org.apache.struts.action.*;
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 org.apache.log4j.*;
public class NoteAction
extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionErrors errors = new ActionErrors();
NoteActionForm form = (NoteActionForm) actionForm;
UserSessionCheck myUserSessionCheck = new UserSessionCheck(form.getSid(),
httpServletRequest);
if (!myUserSessionCheck.checkSession()) {
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());
if (form.getAction().equals("show")) {
Pages myPages = PagesFactory.getInstance();
MessageResources messages = getResources(httpServletRequest);
Locale locale = getLocale(httpServletRequest);
String[] pagessign = {
messages.getMessage(locale, "bbscs.pages.first"),
messages.getMessage(locale, "bbscs.pages.previous"),
messages.getMessage(locale, "bbscs.pages.next"),
messages.getMessage(locale, "bbscs.pages.end")};
myPages.setPagesign(pagessign);
myPages.setPerPageNum(5);
myPages.setPages(Integer.parseInt(form.getPages()));
myPages.setFileName(Sys.getURL() + "noteAction.do?sid=" + form.getSid() +
"&action=" + form.getAction() + "&");
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
myGuestBook.setPages(myPages);
List notelist = myGuestBook.getGuestBookList(null, "myGuestBookList");
String pagebreakstr = myGuestBook.getListPageBreak();
httpServletRequest.setAttribute("notelist", notelist);
httpServletRequest.setAttribute("pagebreakstr", pagebreakstr);
httpServletRequest.setAttribute("fname", form.getFname());
errors = null;
form = null;
myUserSessionCheck = null;
messages = null;
locale = null;
pagessign = null;
myPages = null;
myGuestBookInfo = null;
myGuestBook = null;
notelist = null;
pagebreakstr = null;
return actionMapping.findForward("guestbook");
}
if (form.getAction().equals("read")) {
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
myGuestBookInfo.setID(form.getNoteID());
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
if (myGuestBook.getGuestBook(null, "ID", true) != Sys.RESULT_RIGHT) {
errors.add("nonote", new ActionError("error.nonote"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
if (myGuestBook.getGuestBookInfo().getIsNew() == 0) {
myGuestBook.updateGuestBook(null, "readed");
}
httpServletRequest.setAttribute("myGuestBookInfo",
myGuestBook.getGuestBookInfo());
errors = null;
form = null;
myUserSessionCheck = null;
myGuestBookInfo = null;
myGuestBook = null;
return actionMapping.findForward("readnote");
}
if (form.getAction().equals("add")) {
UserInfo aUserInfo = new UserInfo();
aUserInfo.setUserName(form.getFname());
User aUser = UserFactory.getInstance();
aUser.setUserInfo(aUserInfo);
int result = aUser.getUser(null, "UserName", true);
if (result != Sys.RESULT_RIGHT) {
errors.add("nouser", new ActionError("error.user.nouser"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setFID(aUser.getUserInfo().getID());
myGuestBookInfo.setFname(form.getFname());
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
myGuestBookInfo.setNote(form.getNote());
myGuestBookInfo.setMtype(Integer.parseInt(form.getMtype()));
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
result = myGuestBook.createGuestBook(null);
if (result != Sys.RESULT_RIGHT) {
errors.add("addnote", new ActionError("error.addnote"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("succeed.addnote",
Sys.getURL() + "noteAction.do?sid=" + form.getSid() +
"&action=show", true, false));
errors = null;
form = null;
myUserSessionCheck = null;
aUserInfo = null;
aUser = null;
myGuestBookInfo = null;
myGuestBook = null;
return actionMapping.findForward("forwards");
}
if (form.getAction().equals("del")) {
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
myGuestBookInfo.setID(form.getNoteID());
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
if (myGuestBook.delGuestBook(null, "dela") != Sys.RESULT_RIGHT) {
errors.add("delanote", new ActionError("error.delanote"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
/*
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("succeed.addnote",
Sys.getURL() + "noteAction.do?sid=" + form.getSid() +
"&action=show"));*/
errors = null;
//form = null;
myUserSessionCheck = null;
myGuestBookInfo = null;
myGuestBook = null;
//return actionMapping.findForward("forwards");
ActionForward f = new ActionForward("/noteAction.do?sid=" + form.getSid() +
"&action=show", true);
return f;
}
if (form.getAction().equals("dels")) {
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
myGuestBook.setDelGuestBookIDs(form.getNoteIDs());
if (myGuestBook.delGuestBook(null, "dels") != Sys.RESULT_RIGHT) {
errors.add("delanote", new ActionError("error.delanote"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
/*
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("succeed.addnote",
Sys.getURL() + "noteAction.do?sid=" + form.getSid() +
"&action=show"));*/
errors = null;
//form = null;
myUserSessionCheck = null;
myGuestBookInfo = null;
myGuestBook = null;
//return actionMapping.findForward("forwards");
ActionForward f = new ActionForward("/noteAction.do?sid=" + form.getSid() +
"&action=show", true);
return f;
}
if (form.getAction().equals("delall")) {
GuestBookInfo myGuestBookInfo = new GuestBookInfo();
myGuestBookInfo.setUserID(myUserSessionCheck.getUserID());
myGuestBookInfo.setUname(myUserSessionCheck.getUserName());
GuestBook myGuestBook = GuestBookFactory.getInstance();
myGuestBook.setGuestBookInfo(myGuestBookInfo);
if (myGuestBook.delGuestBook(null, "delAll") != Sys.RESULT_RIGHT) {
errors.add("delanote", new ActionError("error.delanote"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
/*
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("succeed.addnote",
Sys.getURL() + "noteAction.do?sid=" + form.getSid() +
"&action=show"));*/
errors = null;
//form = null;
myUserSessionCheck = null;
myGuestBookInfo = null;
myGuestBook = null;
//return actionMapping.findForward("forwards");
ActionForward f = new ActionForward("/noteAction.do?sid=" + form.getSid() +
"&action=show", true);
return f;
}
return actionMapping.findForward("error");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -