?? notemag.java
字號(hào):
package com.yhcms.manage.note.action;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
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.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.yhcms.db.DBConnException;
import com.yhcms.manage.page.Pages;
import com.yhcms.note.dao.NoteDaoIm;
import com.yhcms.note.itface.NoteDao;
import com.yhcms.utils.ReqUtils;
/**
* <p>Title:系統(tǒng)后臺(tái)留言管理Action</p>
* <li>取得系統(tǒng)的所有留言列表</li>
* <br><b>CopyRight: yyhweb[由由華網(wǎng)]</b>
* @author stephen
* @version YH-2.0
*/
public class NoteMag extends Action {
public ActionForward execute(ActionMapping actionmapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
Logger yhlog = Logger.getLogger(NoteMag.class.getName());
ActionMessages errors = new ActionMessages();
String info = "";
int anId = 0;
int curPage = 0;
int pageSize = 20; // pagesize 可以由管理員再后臺(tái)定義,此處有待改善
int begin = 0; // 開(kāi)始查詢(xún)的位置
info = ReqUtils.getString(request,"info");
anId = ReqUtils.getInt(request,"nId");
curPage = ReqUtils.getInt(request,"curPage"); // 當(dāng)前頁(yè)數(shù)
List nList = null;
int total = 0; // 留言總數(shù)
String link = ""; // 部分相同鏈接
String pageInfo = "";// 分頁(yè)后得到的字符串結(jié)果
Pages pages = null;
NoteDao ndao = NoteDaoIm.getInstance();
if(curPage>1){ // 如果不是第一頁(yè),則從該頁(yè)的第一條開(kāi)始
begin = (curPage-1)*pageSize;
}
try {
// 刪除留言
if(info.equals("delete")){
if(anId>0){
if(ndao.delNote(anId)){ // 刪除留言成功
return actionmapping.findForward("DeleteOk");
}
}
// 刪除留言出錯(cuò)或者artId<=0的話,記錄一個(gè)錯(cuò)誤.
yhlog.info("Delete a note successfully.");
errors.add("admin.note.del.fail",new ActionMessage("admin.note.del.fail"));
saveErrors(request,errors);
return actionmapping.findForward("Success");
}
// 更新留言
if(info.equals("answer")){
if(anId>0){
// nId由URL傳到下一個(gè)畫(huà)面
return actionmapping.findForward("Answer");
}
// 更新留言出錯(cuò)或者artId<=0的話,記錄一個(gè)錯(cuò)誤.
yhlog.info("Answer a note unsuccessfully.");
errors.add("admin.note.answer.fail",new ActionMessage("admin.note.answer.fail"));
saveErrors(request,errors);
return actionmapping.findForward("Success");
}
// 瀏覽所有留言
link = "NoteMag.html?";
total = ndao.getNoteNum();
nList = ndao.getAllNoteDto(begin,pageSize);
pages = new Pages(total,curPage,pageSize,link);
pageInfo = pages.getPageInfo();
} catch (DBConnException e) {
yhlog.warn("Manage system note,throw an Exception!");
}
// 判斷分頁(yè)信息是否為空
if((pageInfo==null) || (pageInfo.equals(""))){
StringBuffer sb = new StringBuffer();
sb.append("<table class='tab' width=100% height=100% cellSpacing=0 cellPadding=0>");
sb.append("<tr><td>");
sb.append(" ");
sb.append("共");
sb.append("<b style=font-size:10pt>");
sb.append(1);
sb.append("</b>");
sb.append("頁(yè) ");
sb.append("<b style=font-size:10pt>");
sb.append(total);
sb.append("</b>");
sb.append("個(gè)記錄 ");
sb.append("</td></tr>");
sb.append("<table>");
pageInfo = sb.toString();
sb = null;
}
request.setAttribute("noteList",nList);
request.setAttribute("pageInfo",pageInfo);
return actionmapping.findForward("Success");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -