?? manageaction.java
字號:
try {
//上傳圖片
// 新建??個SmartUpload對象
SmartUpload su = new SmartUpload();
// 上傳初始??
su.initialize(request.getSession().getServletContext(),
(HttpServletRequest) request,
(HttpServletResponse) response);
// 設(shè)定上傳限制
// 1.限制每個上傳文件的最大長度???
su.setMaxFileSize(1000000);
// 2.限制總上傳數(shù)據(jù)的長度??
// su.setTotalMaxFileSize(20000);
// 3.設(shè)定允許上傳的文件(通過擴(kuò)展名限制),僅允許doc,txt文件??
su.setAllowedFilesList("jpg,gif,JPG,GIF");
// 4.設(shè)定禁止上傳的文件(通過擴(kuò)展名限制),禁止上傳帶有exe,bat,jsp, htm, html擴(kuò)展名的文件和沒有擴(kuò)展名的文?? ??
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上傳文件
su.upload();
// 將上傳文件全部保存到指定目錄
su.save("/images/logoes");
// 逐一提取上傳文件信息,同時可保存文件??
for (int i = 0; i < su.getFiles().getCount(); i++) {
SmartFile file = su.getFiles().getFile(i);
// 若文件不存在則繼??
if (file.isMissing()) {
continue;
}
//得到文件??
String fileName = su.getFileNames()[i];
//生成縮小圖片
ImgUtil iutil = new ImgUtil();
String tfileName = fileName.substring(0, fileName.indexOf(".")) +
"_s." + file.getFileExt();
iutil.reduce(getServlet().getServletContext().getRealPath("/") +
fileName,
getServlet().getServletContext().getRealPath("/") +
tfileName, 85, 18);
//刪除原文??
File f = new File(getServlet().getServletContext().getRealPath(
"/") +
fileName);
f.delete();
new GoodsMgr().updateBrandLogo1(BaseUtil.toInt(su.getRequest().
getParameter("brand_id")), tfileName);
}
} catch (Exception ex) {
throw new AppException(ex);
}
return mapping.findForward("doLogo1Modify");
}
public ActionForward toLogo2Modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
GenericVO bvo = new GoodsMgr().getBrandDetail(BaseUtil.toInt(request.
getParameter("brand_id")));
request.setAttribute("bean", bvo);
return mapping.findForward("toLogo2Modify");
}
public ActionForward doLogo2Modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
try {
//上傳圖片
// 新建??個SmartUpload對象
SmartUpload su = new SmartUpload();
// 上傳初始??
su.initialize(request.getSession().getServletContext(),
(HttpServletRequest) request,
(HttpServletResponse) response);
// 設(shè)定上傳限制
// 1.限制每個上傳文件的最大長度???
su.setMaxFileSize(1000000);
// 2.限制總上傳數(shù)據(jù)的長度??
// su.setTotalMaxFileSize(20000);
// 3.設(shè)定允許上傳的文件(通過擴(kuò)展名限制),僅允許doc,txt文件??
su.setAllowedFilesList("jpg,gif,JPG,GIF");
// 4.設(shè)定禁止上傳的文件(通過擴(kuò)展名限制),禁止上傳帶有exe,bat,jsp, htm, html擴(kuò)展名的文件和沒有擴(kuò)展名的文?? ??
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上傳文件
su.upload();
// 將上傳文件全部保存到指定目錄
su.save("/images/logoes");
// 逐一提取上傳文件信息,同時可保存文件??
for (int i = 0; i < su.getFiles().getCount(); i++) {
SmartFile file = su.getFiles().getFile(i);
// 若文件不存在則繼??
if (file.isMissing()) {
continue;
}
//得到文件??
String fileName = su.getFileNames()[i];
//生成縮小圖片
ImgUtil iutil = new ImgUtil();
String tfileName = fileName.substring(0, fileName.indexOf(".")) +
"_s." + file.getFileExt();
iutil.reduce(getServlet().getServletContext().getRealPath("/") +
fileName,
getServlet().getServletContext().getRealPath("/") +
tfileName, 140, 30);
//刪除原文??
File f = new File(getServlet().getServletContext().getRealPath(
"/") +
fileName);
f.delete();
new GoodsMgr().updateBrandLogo2(BaseUtil.toInt(su.getRequest().
getParameter("brand_id")), tfileName);
}
} catch (Exception ex) {
throw new AppException(ex);
}
return mapping.findForward("doLogo2Modify");
}
//用戶
public ActionForward toUserManage(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
//設(shè)置查詢條件
GenericVO gvo = new GenericVO();
ListVO lvo = new ListVO();
gvo = AppUtil.convertParameters(request, gvo); //將request 中的參數(shù)設(shè)置到cvo\uFFFD?
lvo.setItemsPerPage(30);
lvo = AppUtil.processListVO(lvo, request); //設(shè)置ListVO
gvo.setListVO(lvo);
//查詢數(shù)據(jù)
lvo = new UserMgr().searchUser(gvo);
gvo.setListVO(lvo);
//設(shè)置頁面數(shù)據(jù)
request.setAttribute("bean", gvo);
return mapping.findForward("toUserManage");
}
//公告
public ActionForward toBulletinManage(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
return mapping.findForward("toBulletinManage");
}
public ActionForward toBulletinEditor(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
File f = new File(getServlet().getServletContext().getRealPath("/") +
"htmlet/bulletin.htm");
if (!f.exists()) {
f.createNewFile();
}
//讀取公告文件
BufferedReader br = new BufferedReader(new InputStreamReader(new
FileInputStream(getServlet().getServletContext().getRealPath(
"/") +
"htmlet/bulletin.htm"), "UTF-8"));
String data = null;
String content = "";
while ((data = br.readLine()) != null) {
content = content + data;
}
br.close();
request.setAttribute("CONTENT", content);
return mapping.findForward("toBulletinEditor");
}
public ActionForward doBulletinModify(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
String content = request.getParameter("content");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(
getServlet().getServletContext().getRealPath("/") +
"htmlet/bulletin.htm"), "UTF-8");
osw.write(content, 0, content.length());
osw.flush();
osw.close();
return mapping.findForward("doBulletinModify");
}
//排行??
public ActionForward toTopManage(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
Vector r = new GoodsMgr().getTopByType(0);
//得到每個排行榜的內(nèi)容
GenericVO tvo = null;
String fileName = null;
File f = null;
for (int i = 0; i < r.size(); i++) {
tvo = (GenericVO) r.elementAt(i);
fileName = getServlet().getServletContext().getRealPath("/") +
"htmlet/top_" + tvo.getItem("TOP_ID") + ".htm";
f = new File(fileName);
if (!f.exists()) {
f.createNewFile();
}
//讀取排行榜文??
BufferedReader br = new BufferedReader(new InputStreamReader(new
FileInputStream(fileName), "UTF-8"));
String data = null;
String content = "";
while ((data = br.readLine()) != null) {
content = content + data;
}
br.close();
tvo.add("CONTENT", content);
}
request.setAttribute("RESULT", r);
return mapping.findForward("toTopManage");
}
public ActionForward toTopAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
return mapping.findForward("toTopAdd");
}
public ActionForward doTopAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
GenericVO gvo = new GenericVO();
gvo = AppUtil.convertParameters(request, gvo); //將request 中的參數(shù)設(shè)置到cvo
new GoodsMgr().addTop(gvo);
return mapping.findForward("doTopAdd");
}
public ActionForward toTopModify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
GenericVO tvo = new GoodsMgr().getTopDetail(BaseUtil.toInt(request.
getParameter("top_id")));
request.setAttribute("bean", tvo);
return mapping.findForward("toTopModify");
}
public ActionForward doTopModify(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
GenericVO gvo = new GenericVO();
gvo = AppUtil.convertParameters(request, gvo); //將request 中的參數(shù)設(shè)置到cvo
new GoodsMgr().modifyTop(gvo);
this.genIndexTop();
return mapping.findForward("doTopModify");
}
public ActionForward doTopDelete(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
new GoodsMgr().deleteTop(BaseUtil.toInt(request.getParameter("top_id")));
this.genIndexTop();
return mapping.findForward("doTopDelete");
}
public ActionForward toTopEdit(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
return mapping.findForward("toTopEdit");
}
public ActionForward doTopEdit(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
String fileName = getServlet().getServletContext().getRealPath("/") +
"htmlet/top_" + request.getParameter("top_id") +
".htm";
String content =
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" +
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -