📄 upuserimgaction.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.*;
public class UpuserImgAction
extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionErrors errors = new ActionErrors();
UpuserImgActionForm form = (UpuserImgActionForm) 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("upload")) {
return actionMapping.findForward("upload");
}
if (form.getAction().equals("uploaddo")) {
FormFile file = form.getForm_data();
//boolean isHavePic = false;
if (file != null && file.getFileName() != null &&
file.getFileName().length() > 0) {
if (Util.isAllowFile("pic", file.getFileName()) &&
file.getFileSize() > 0 &&
file.getFileSize() <= (Sys.SYSINFO.UPIMGSIZE * 1024)) {
String picFileName = String.valueOf(myUserSessionCheck.getUserID()) +
String.valueOf(Util.getaLongTime()) +
Util.getFileExt(file.getFileName()); ;
if (myUserSessionCheck.getUser().getUserInfo().getHavePic() == 1) {
java.io.File myPicFile = new java.io.File(Util.getUserImgPath(
myUserSessionCheck.getUserName(), myUserSessionCheck.getUserID()) +
myUserSessionCheck.getUser().getUserInfo().getPicFileName());
if (myPicFile.exists()) {
myPicFile.delete();
}
}
try {
InputStream stream = file.getInputStream();
OutputStream bos = new FileOutputStream(Util.getUserImgPath(
myUserSessionCheck.getUserName(), myUserSessionCheck.getUserID()) +
picFileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
}
catch (Exception e) {
}
UserInfo aUserInfo = myUserSessionCheck.getUser().getUserInfo();
aUserInfo.setHavePic(1);
aUserInfo.setPicFileName(picFileName);
User aUser = myUserSessionCheck.getUser();
aUser.setUserInfo(aUserInfo);
aUser.updateUser(null, "userPic");
UserPicInfo aUserPicInfo = new UserPicInfo();
aUserPicInfo.setID(String.valueOf(aUserInfo.getID()) +
String.valueOf(Util.getaLongTime()));
aUserPicInfo.setUserID(aUserInfo.getID());
aUserPicInfo.setUserName(aUserInfo.getUserName());
aUserPicInfo.setPicFileName(picFileName);
UserPic aUserPic = UserPicFactory.getInstance();
aUserPic.setUserPicInfo(aUserPicInfo);
if (aUserPic.getUserPic(null, "UserID", false) ==
Sys.RESULT_OBJECTNOEXISTEXCEPTION) {
aUserPic.createUserPic(null);
}
else {
aUserPic.updateUserPic(null, "PicFileName");
}
/*
httpServletRequest.setAttribute("aForwardInfo",
new ForwardInfo("",
Sys.getURL() + "inAction.do?sid=" + form.getSid()));
return actionMapping.findForward("forwards");*/
ActionForward f = new ActionForward("/inAction.do?sid=" + form.getSid(), true);
return f;
}
else {
errors.add("upnotice",
new ActionError("post.upnotice",
String.valueOf(Sys.SYSINFO.UPIMGSIZE)));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
}
}
return actionMapping.findForward("error");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -