日期:2014-05-18  浏览次数:20779 次

Struts重定向页面问题
问题:

  点击主页面一个查询按钮,我用window.showDialogModal('search.jsp') 弹出search.jsp页面,
  在search.jsp页面输入好查询条件点击提交,便进入ACTION进行处理后,便用mapping.findForward('display')
  通过配置文件再转到主页面。(就这时问题出现了,他不是刷新主页面 而是重新又打开了个主页面)


需求:让他重新定向到原主页面,不让他新打开。

说明:请勿让我绕道行走,如果不用window.showDialogModal打开 直接用ACTION就没问题。但我现在就像搞明白类似于
  window.open等这种新打开的页面,怎么重新定向到主页面。
   
 

------解决方案--------------------
我好像做过这样的东西,给你一些代码不知道有没有用
这是一个userlist.jsp页面,其中有一个按钮是增加用户的,点击该按钮会调用一段js
function adduser()
{
  
var returnValue;
  
returnValue = window.showModalDialog('../userAdmin/userAdminAction.do?action=initAdd',returnValue,'dialogWidth:600px; dialogHeight:750px; center:Yes; resizable: Yes; help: No;');
  
if (returnValue=='true')
{
alert('<bean:message bundle="common" key="new.success"/>');
window.location="userList.jsp"; 
}
}
我这里的action处理完毕后会导向一个adduser.jsp页面,这个action只是为了在adduser.jsp显示时做一些处理,然后,我在adduser.jsp中使用了ajax
核心代码如下
var xmlHttp = init();
xmlHttp.open("POST", url, false);
xmlHttp.send();
if (xmlHttp.responseText =="repeat")
{
alert('<bean:message bundle="common" key="username.repeat"/>');
return;
}
else
{
returnValue='true';
window.close();
}
adduser.jsp也是提交到一个action的,但是这个action返回值为空,但是里面有如下的语句response.getWriter().write("success");这个语句
会由xmlHttp.responseText 获得的,此时会返回 returnValue='true'这样的话,页面就又返回到userlist.jsp了,不知道说清楚没有。

------解决方案--------------------
这个是adduser.jsp提交到的action
public ActionForward saveUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{

/**登录名*/
String loginname=request.getParameter("loginname");

/**全名*/
String name=request.getParameter("name");

/**密码*/
String password=request.getParameter("password");

/**部门*/
String department=request.getParameter("department");


/**描述*/
String description=request.getParameter("description");



/**所在组*/
String selectedgroup=request.getParameter("selectedgroup");

----------略------------------

boolean lgname=userService.getUser(hql.toString());


if(!lgname)
{
response.getWriter().write("repeat");

return null;
}


userService.saveUser(user,group,paramIds,selectValues,rootpath,resourceService);
-----略---------
return null;

}
------解决方案--------------------
在主页面上设置target
------解决方案--------------------
在head标签中加入
HTML code
<base href="<%=basePath%>" target="_self">

------解决方案--------------------
原因: 你用window.showDialogModal('search.jsp') 弹出search.jsp页面,那你提交的当然是search.jsp中的数据,那跳转当然也跳转'search.jsp'
解决办法: search.jsp中的提交交由打开他的页面去做,可以在打开他的页面上加入hidden框,search.jsp中的提交按钮用来对打开他的页面中的hidden进行付值(windows.opener.document.getElementById("xxxx") = document.getElementById("xxxx")),并且调用window.opener.submit();把hidden框提交到后台处理
------解决方案--------------------
学习~~~
------解决方案--------------------