JSP页面中新增完一个项目后,刷新页面出现的问题

Alvan 05-07-06

我是用struts做的,action中的add()方法来新增完某一项东西后,从add页面跳转到list页面,然后刷新list页面,结果又跳到原来的add页面,并且显示新增项目重复(我设定了不能重复)。请问是什么问题?该如何解决?

我的action里的add()方法是这样的:
public ActionForward addSkill(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws SystemException,SkillExistsException{

SkillForm skillForm = (SkillForm)form;

//增加技能信息
SkillVO skillVO = new SkillVO();
skillVO.setSkillName(skillForm.getSkillName());
skillVO.setSkillExplain(skillForm.getSkillExplain());
skillVO.setSkillRequirementGist(skillForm.getSkillRequirement());
skillVO.setEvaluateModeID(Long.parseLong(skillForm.getEvaluateModeID()));

SysManageFacade sysmanage = new SysManageFacade();

try {
sysmanage.addSkill(skillVO);
logRecord(request,"增加了一个技能",LogTypeConst.SKILL_LOG);
ArrayList evaluateModeList = sysmanage.getEvaluateModeList(); //获取评估方式列表
} catch (SystemException e) {
return mapping.findForward(ForwardKeyConstant.ERROR_KEY);
} catch (ApplicationException e) {
request.setAttribute("msg","exist");
return showSkillAddPage(mapping,form,request,response);
}

PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(1);
SkillSearchDTO dto = new SkillSearchDTO();

//准备查询条件及翻页信息
HttpSession session = request.getSession();
session.setAttribute(EimsSessionConst.SKILL_SEARCH_DTO,dto);
session.setAttribute(EimsSessionConst.PAGE_INFO,pageInfo);

this.prepareSkillList(skillForm,request,response); //调用prepareSkillList方法
return mapping.findForward(PAGE_SKILL_LIST);
}

aill
2005-07-06 15:48

“从add页面跳转到list页面”你在这个跳转的时候使用了
forward(request,response),所以你的页面的location没有改变,所以刷新的时候其实还是执行了提交的操作;
你可以使用response.sendRedirect(location)

Alvan
2005-07-06 16:29

请问具体怎么写呢?

我刚看到另外一篇文章
http://www.javaresearch.org/article/showarticle.jsp?column=106&thread=24634
这个办法好还是你这个办法好呢?
用他这个办法,我不知道/recordList.do请求需要一个参数是record_id=xxx是什么意思?
因为我要用到request,所以只改config不行

Alvan
2005-07-06 16:30

你的意思是不是直接用response来代替return.mapping...?
但我的add方法需要返回值,该怎么操作?

Alvan
2005-07-06 16:46

把我另一个要用到的方法也传上来

private void prepareSkillList(ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();

//从sessssion中获取查询条件及翻页信息
SkillSearchDTO skillSearchDTO = new SkillSearchDTO();
skillSearchDTO = (SkillSearchDTO)session.getAttribute(EimsSessionConst.SKILL_SEARCH_DTO);
PageInfo pageInfo = new PageInfo();
pageInfo = (PageInfo)session.getAttribute(EimsSessionConst.PAGE_INFO);

//根据查询条件及翻页信息获取技能列表
SysManageFacade sysmanageFacade = new SysManageFacade();
ArrayList skillList = sysmanageFacade.getSkillList(skillSearchDTO,pageInfo);
ArrayList evaluateModeList = sysmanageFacade.getEvaluateModeList();

//将获取的技能列表及评估方式列表保存至request中
request.setAttribute(EimsSessionConst.SKILLLIST, skillList);
request.setAttribute(EimsSessionConst.EVALUATEMODELIST, evaluateModeList);
}