📄 dsjaction.java
字号:
package swdyx.bhdt;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import swdyx.common.*;
import java.util.*;
import javax.sql.*;
public class DsjAction
extends Action {
private static final int PAGE_LENGTH = 10;
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest
httpServletRequest,
HttpServletResponse httpServletResponse) {
ActionForward myforward = null;
String myaction = actionMapping.getParameter();
if ("DsjList".equals(myaction)) {
myforward = performDsjList(actionMapping, actionForm,
httpServletRequest,
httpServletResponse);
}
else if ("DsjCk".equals(myaction)) {
myforward = performDsjCk(actionMapping, actionForm,
httpServletRequest,
httpServletResponse);
}
return myforward;
}
//进入大事记信息页面
public ActionForward performDsjList(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse
httpServletResponse) {
//定义session
HttpSession mySession = httpServletRequest.getSession();
//设置初始查询条件
mySession.setAttribute("DSJ", "1=1");
//清空页码session
mySession.setAttribute("PAGE", "");
try {
// 连接数据源
DataSource ds = Datasource.getDataSource();
List dsj = null;
dsj = SperatePage(actionMapping, actionForm, httpServletRequest,
httpServletResponse);
httpServletRequest.setAttribute("TYPE", dsj);
}
catch (Exception e) {
return actionMapping.findForward("error");
}
return actionMapping.findForward("success");
} //进入大事记信息页面 方法执行完毕
//打开列表时所用的分页方法 此方法为通用方法
public List SperatePage(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
List dsj = null;
try {
//连接数据源
DataSource ds = Datasource.getDataSource();
//建立BhdtDao的对象bhdtDao
DsjDao dsjDao = new DsjDao(ds);
int offset; //申明页码变量
//获取页面参数pager.offset 如:10 表示第二页
String pageOffset = httpServletRequest.getParameter("pager.offset");
//定位分页符
//定义页码session
HttpSession pagesession = httpServletRequest.getSession();
//判断页码是否存在
if (pageOffset == null || pageOffset.equals("")) { //如果不能从页面上取到页码或者取到的页码为空 则从第一次进来时设置的页码session中取
pageOffset = pagesession.getAttribute("PAGE").toString();
}
//把取得的页码放入session
pagesession.setAttribute("PAGE", pageOffset);
if (pageOffset == null || pageOffset.equals("")) { //如果此时获得的页码还为空 则设置offset为0 否则offest=Integer.parseInt(pageOffset
offset = 0;
}
else {
offset = Integer.parseInt(pageOffset);
}
int size = 0;
//当前url路径
String url = httpServletRequest.getContextPath() + actionMapping.getPath() +
".do";
//获取当前的查询条件 //从第一次进入该模块设置的session 中取 或者 从检索条件中设置的session 中取
HttpSession mySession = httpServletRequest.getSession();
String sFilter;
sFilter = (String) mySession.getAttribute("DSJXX");
//所有记录数
size = dsjDao.countlist(sFilter);
//分页显示连接 调用分页方法
String pagerHeader = Separatepage.geneHtml(offset, size, PAGE_LENGTH, url);
httpServletRequest.setAttribute("pagerHeader", pagerHeader);
dsj = dsjDao.list(offset, PAGE_LENGTH, sFilter);
}
catch (Exception e) {
}
return dsj;
} //打开列表时所用的分页方法 方法执行完毕
//打开各大事记信息页面
public ActionForward performDsjCk(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse
httpServletResponse) {
//获取页面传来参数
String xh = httpServletRequest.getParameter("xh");
try {
// 连接数据源
DataSource ds = Datasource.getDataSource();
//查看各大事记的具体信息
DsjDao dsjDao = new DsjDao(ds);
BhdtBo bhdtBo = dsjDao.retrieve(xh);
httpServletRequest.setAttribute("DSJ", bhdtBo);
}
catch (Exception e) {
return actionMapping.findForward("error");
}
return actionMapping.findForward("success");
} //end
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -