You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

切换ModelAndView控制器后「返回结果列表」链接失效求助

点击「返回结果列表」链接返回空白页问题排查

问题背景

切换为ModelAndView控制器格式后,搜索结果页头部的「返回结果列表」链接失效,点击仅返回空白页。调试控制器后仍未明确空白页成因,通过F12网络分析发现,发送给GlobalNavigationController的请求Payload中未传递JavaScript定义的userAction参数,怀疑是ModelAndView结构配置导致参数未传递。

相关代码

searchResultHeading.jsp(包含目标链接的JSP)

<%if(ApplicationBean.getBizActivityAuthorizations().ResultBasicInfo() && !ApplicationBean.isInExternalAppContext()) { %>
    &nbsp;| <a href="javaScript:returnToResultList();" class=sm>Return to Result list</a>
<% } %>     
</td>
</tr>

Header.jsp(包含returnToResultList函数的公共JSP)

function returnToResultList()
{
    <%if(ApplicationBean.isSearchResultsAvailable()){
    %>
        gotoSearchResults(document.userSelection);
    <%
    }else if(ApplicationBean.isMarketingListAvailable()){
    %>
        gotoListParticipants();
    <%
    }%> 
}
function gotoSearchResults(searchForm)
{
    searchForm.userAction.value = "<%=myLiterals.USER_ACTION_RETURN_TO_SEARCH_RESULTS_PAGE%>";
    searchForm.action="/mySite/GlobalNavigationController";
    searchForm.submit();
    return true;
}
@Controller
public class GlobalNavigationController {

@Autowired
private CustomerListController customerListController;

@RequestMapping(path="/GlobalNavigationController", method={RequestMethod.GET, RequestMethod.POST})
   public ModelAndView doGet(HttpSession session, HttpServletRequest req, HttpServletResponse res) throws Exception
    {
        SiteBean myBean = new myBean();
        try
        {
            RequestMapper.MapToBean(req,myBean);
            if (myBean.getUserAction().equals(myLiterals.USER_ACTION_1))
            {
                return null;
            }
            else if(myBean.getUserAction().equals(myLiterals.USER_ACTION_2))
            {
                GlobalNavigationUCService.processSideNav();
                GlobalNavigationUCService.resetDisPlayOrder();
                return maintainController.doGet(session, req, res);
            }
            else if (myBean.getUserAction().equals(myLiterals.USER_ACTION_3))
            {
                GlobalNavigationUCService.processSideNavInitiateSearch();
                GlobalNavigationUCService.resetDisPlayOrder();
                return SearchController.doGet(session, req, res);
            }
            else if(myBean.getUserAction().equalsIgnoreCase(myLiteral.USER_ACTION_4))
            {
                GlobalNavigationUCService.processSideNavInitiateSearch();
                GlobalNavigationUCService.processTabsGoToResults();
                GlobalNavigationUCService.resetDisPlayOrder();
                return ProfileController.doGet(session,req,res);
            }
            else if (myBean.getUserAction().equals(myLiterals.USER_ACTION_RETURN_TO_SEARCH_RESULTS_PAGE))
            {
                GlobalNavigationUCService.processTabsGoToResults();
                return customerListController.doGet(session, req, res);
            }

排查发现

通过浏览器F12网络面板查看请求详情,发现提交到/mySite/GlobalNavigationController的请求Payload中并未包含JavaScript设置的userAction参数,导致控制器无法匹配到对应的处理分支。

可能的解决方向

  • 检查页面中是否存在name="userSelection"的表单:确认document.userSelection能正确获取到表单对象,若表单结构在控制器切换后发生变化,需修正JavaScript中的表单引用。
  • 验证myLiterals.USER_ACTION_RETURN_TO_SEARCH_RESULTS_PAGE的渲染值:查看页面源码中的gotoSearchResults函数,确认userAction的赋值是否为预期的字符串。
  • 检查RequestMapper.MapToBean的参数映射逻辑:确认请求参数能正确映射到myBean的userAction字段,若映射规则有误需调整。
  • 确认控制器分支的完整性:检查代码中是否存在未处理的else分支,若userAction未匹配任何条件,控制器可能返回空的ModelAndView导致空白页。
  • 验证customerListController.doGet的返回值:确认该方法返回了有效的ModelAndView对象,包含正确的视图和模型数据。

内容的提问来源于stack exchange,提问作者Rob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 15:03:20