網站中友情連結的部分程式碼,表示看不懂
阿新 • • 發佈:2019-01-09
package com.daowen.action;
public class FriendlinkAction extends PageActionBase {
public void onLoad() {
}
/********************************************************
****************** 資訊登出監聽支援*****************************
*********************************************************/
public void delete() {
String id = request.getParameter("id");
DALBase.delete("friendlink", " where id=" + id);
binding();
}
/*************************************************************
**************** 儲存動作監聽支援******************************
**************************************************************/
public void save() {
String title = request.getParameter("title");
String href = request.getParameter("href");
SimpleDateFormat sdffriendlink = new SimpleDateFormat("yyyy-MM-dd");
Friendlink friendlink = new Friendlink();
friendlink.setTitle(title == null ? "" : title);
friendlink.setHref(href == null ? "" : href);
DALBase.save(friendlink);
// 儲存附件
attachements(request, response,
new Integer(friendlink.getId()).toString());
// 繫結資料
binding();
}
/******************************************************
*********************** 內部附件支援*********************
*******************************************************/
public void attachements(HttpServletRequest request,
HttpServletResponse response, String belongid) {
DALBase.delete("attachement", MessageFormat.format(
" where belongid=''{0}'' and belongtable=''friendlink'' ",
belongid));
String[] photos = request.getParameterValues("fileuploaded");
if (photos == null)
return;
for (int i = 0; i < photos.length; i++) {
Attachement a = new Attachement();
a.setType("images");
a.setPubtime(new Date());
a.setBelongfileldname("id");
a.setFilename(photos[i]);
a.setBelongid(belongid);
a.setBelongtable("friendlink");
a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
+ a.getFilename());
a.setTitle(a.getFilename());
DALBase.save(a);
}
}
/******************************************************
*********************** 更新內部支援*********************
*******************************************************/
public void update() {
String id = request.getParameter("id");
if (id == null)
return;
Friendlink friendlink = (Friendlink) DALBase.load(Friendlink.class,
new Integer(id));
if (friendlink == null)
return;
String title = request.getParameter("title");
String href = request.getParameter("href");
SimpleDateFormat sdffriendlink = new SimpleDateFormat("yyyy-MM-dd");
friendlink.setTitle(title);
friendlink.setHref(href);
DALBase.update(friendlink);
attachements(request, response,
new Integer(friendlink.getId()).toString());
binding();
}
/******************************************************
*********************** 載入內部支援*********************
*******************************************************/
public void load() {
//
String id = request.getParameter("id");
String actiontype = "save";
dispatchParams(request, response);
if (id != null) {
Friendlink friendlink = (Friendlink) DALBase.load("friendlink",
"where id=" + id);
if (friendlink != null) {
request.setAttribute("friendlink", friendlink);
}
actiontype = "update";
request.setAttribute("id", id);
}
request.setAttribute("actiontype", actiontype);
try {
request.getRequestDispatcher("friendlinkadd.jsp").forward(request,
response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/******************************************************
*********************** 資料繫結內部支援*********************
*******************************************************/
public void binding() {
String filter = "";
//
String title = request.getParameter("title");
if (title != null)
filter = " where title like '%" + title + "%' ";
//
int pageindex = 1;
int pagesize = 10;
// 獲取當前分頁
String currentpageindex = request.getParameter("currentpageindex");
// 當前頁面尺寸
String currentpagesize = request.getParameter("pagesize");
// 設定當前頁
if (currentpageindex != null)
pageindex = new Integer(currentpageindex);
// 設定當前頁尺寸
if (currentpagesize != null)
pagesize = new Integer(currentpagesize);
List<Friendlink> listfriendlink = DALBase.getPageEnity("friendlink",
filter, pageindex, pagesize);
int recordscount = DALBase.getRecordCount("friendlink",
filter == null ? "" : filter);
request.setAttribute("listfriendlink", listfriendlink);
PagerMetal pm = new PagerMetal(recordscount);
// 設定尺寸
pm.setPagesize(pagesize);
// 設定當前顯示頁
pm.setCurpageindex(pageindex);
// 設定分頁資訊
request.setAttribute("pagermetal", pm);
// 分發請求引數
dispatchParams(request, response);
try {
request.getRequestDispatcher("/admin/friendlinkmanager.jsp")
.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class FriendlinkAction extends PageActionBase {
public void onLoad() {
}
/********************************************************
****************** 資訊登出監聽支援*****************************
*********************************************************/
public void delete() {
String id = request.getParameter("id");
DALBase.delete("friendlink", " where id=" + id);
binding();
}
/*************************************************************
**************** 儲存動作監聽支援******************************
**************************************************************/
public void save() {
String title = request.getParameter("title");
String href = request.getParameter("href");
SimpleDateFormat sdffriendlink = new SimpleDateFormat("yyyy-MM-dd");
Friendlink friendlink = new Friendlink();
friendlink.setTitle(title == null ? "" : title);
friendlink.setHref(href == null ? "" : href);
DALBase.save(friendlink);
// 儲存附件
attachements(request, response,
new Integer(friendlink.getId()).toString());
// 繫結資料
binding();
}
/******************************************************
*********************** 內部附件支援*********************
*******************************************************/
public void attachements(HttpServletRequest request,
HttpServletResponse response, String belongid) {
DALBase.delete("attachement", MessageFormat.format(
" where belongid=''{0}'' and belongtable=''friendlink'' ",
belongid));
String[] photos = request.getParameterValues("fileuploaded");
if (photos == null)
return;
for (int i = 0; i < photos.length; i++) {
Attachement a = new Attachement();
a.setType("images");
a.setPubtime(new Date());
a.setBelongfileldname("id");
a.setFilename(photos[i]);
a.setBelongid(belongid);
a.setBelongtable("friendlink");
a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
+ a.getFilename());
a.setTitle(a.getFilename());
DALBase.save(a);
}
}
/******************************************************
*********************** 更新內部支援*********************
*******************************************************/
public void update() {
String id = request.getParameter("id");
if (id == null)
return;
Friendlink friendlink = (Friendlink) DALBase.load(Friendlink.class,
new Integer(id));
if (friendlink == null)
return;
String title = request.getParameter("title");
String href = request.getParameter("href");
SimpleDateFormat sdffriendlink = new SimpleDateFormat("yyyy-MM-dd");
friendlink.setTitle(title);
friendlink.setHref(href);
DALBase.update(friendlink);
attachements(request, response,
new Integer(friendlink.getId()).toString());
binding();
}
/******************************************************
*********************** 載入內部支援*********************
*******************************************************/
public void load() {
//
String id = request.getParameter("id");
String actiontype = "save";
dispatchParams(request, response);
if (id != null) {
Friendlink friendlink = (Friendlink) DALBase.load("friendlink",
"where id=" + id);
if (friendlink != null) {
request.setAttribute("friendlink", friendlink);
}
actiontype = "update";
request.setAttribute("id", id);
}
request.setAttribute("actiontype", actiontype);
try {
request.getRequestDispatcher("friendlinkadd.jsp").forward(request,
response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/******************************************************
*********************** 資料繫結內部支援*********************
*******************************************************/
public void binding() {
String filter = "";
//
String title = request.getParameter("title");
if (title != null)
filter = " where title like '%" + title + "%' ";
//
int pageindex = 1;
int pagesize = 10;
// 獲取當前分頁
String currentpageindex = request.getParameter("currentpageindex");
// 當前頁面尺寸
String currentpagesize = request.getParameter("pagesize");
// 設定當前頁
if (currentpageindex != null)
pageindex = new Integer(currentpageindex);
// 設定當前頁尺寸
if (currentpagesize != null)
pagesize = new Integer(currentpagesize);
List<Friendlink> listfriendlink = DALBase.getPageEnity("friendlink",
filter, pageindex, pagesize);
int recordscount = DALBase.getRecordCount("friendlink",
filter == null ? "" : filter);
request.setAttribute("listfriendlink", listfriendlink);
PagerMetal pm = new PagerMetal(recordscount);
// 設定尺寸
pm.setPagesize(pagesize);
// 設定當前顯示頁
pm.setCurpageindex(pageindex);
// 設定分頁資訊
request.setAttribute("pagermetal", pm);
// 分發請求引數
dispatchParams(request, response);
try {
request.getRequestDispatcher("/admin/friendlinkmanager.jsp")
.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}