我正在Spring MVC中编写一个应用程序。我正在使用搜索操作并以表格格式在jsp中显示结果,每行都有一个单选按钮,我再次在searchResult.jsp
中有一个更新按钮来更新表中的选定行。
但是在通过我的控制器完成更新操作之后,我想将它重定向到相同的searchResult.jsp
,但是有更新的记录。
请帮助我....
我的第一个给我搜索结果的控制器使用@RequestParams
作为参数。我之所以提到这一点,是因为我搜索了很多内容并找到了再次调用相同搜索控制器的建议,但在我的情况下它不起作用。
我的jsp for search
<!-- sac search -->
<div id="sacSearch">
<div id="searchContact">
<form:form class="form-horizontal paddingTop10" role="form" action="autoRestrictSACSearchResult.htm" id="autoRestSACForm" method="POST">
<div class="form-group">
<label id="sacLabel" for="sac" class="col-sm-3 control-label"><spring:message code="manage.barrying.sac" /></label>
<div class="col-sm-3">
<input class="form-control" type="text" id="sac" name="sac">
</div>
<label id="sacNameLabel" for="sacName" class="col-sm-3 control-label"><spring:message code="manage.barrying.sac.name" /></label>
<div class="col-sm-3">
<input class="form-control" type="text" id="sacName" name="sacName" data-toggle="tooltip" data-placement="right" title=""
data-original-title="Wildcard search - use * symbol">
</div>
</div>
<hr>
<div class="form-group paddingSide30 marginBottom0">
<button type="submit" class="btn btn-default btnStyle floatRight">
<spring:message code="manage.barrying.search" />
</button>
</div>
</form:form>
</div>
</div>
我的第一个搜索控制器
@RequestMapping(value = /autoRestrictSACSearchResult, method = RequestMethod.POST)
@CDBusinessProcess("ThirdPartySACSearch")
public ModelAndView ThirdPartysearchUsingSAC(@RequestParam(value="sac") String sac, @RequestParam(value="sacName") String sacName){
ThreadLocalResources.get().logger().logMessage(E2EMessageGroup.INFO, "ThirdPartySACSearch" + ": searchUsingAccount, sac = "+sac + ", sacName = "+sacName);
ModelAndView modelAndView = new ModelAndView();List<RestrictionBarryingDTO> restricBarryindSACList = null;
restricBarryindSACList = restrictBarryingService.thirdPartygetSACSearchList(sac, sacName);
modelAndView.setViewName("thirdPartySACSearchResult");
modelAndView.addObject("restricBarryindSACList",restricBarryindSACList);
modelAndView.addObject("sac",sac);
modelAndView.addObject("sacName",sacName);
return modelAndView;
}
并且thirdPartySACSearchResult.jsp再次具有如下形式:
<form:form id="sacEditForm" role="form"
action="thirdPartyapplyRemoveBarryingforSac.htm" method="POST">
<c:choose>
<c:when test="${not empty sac and not empty sacName}">
<p>
<strong>Search results for Sales account Code:</strong> ${sac}<strong>
and Sales Account Name:</strong> ${sacName}
</p>
</c:when>
<c:when test="${not empty sac}">
<p>
<strong>Search results for Sales Account Code:</strong> ${sac}
</p>
</c:when>
<c:when test="${not empty sacName}">
<p>
<strong>Search results for Sales Account Name:</strong> ${sacName}
</p>
</c:when>
</c:choose>
<spring:message code="manage.barrying.apply.bar.to"/>
<div class="verticalDivider topScope historyFullWidth">
<table class="tablesorter standardText stripedTableJS">
<thead>
<tr class="greyBackground">
<th scope="col" class="width10 hideBackgroundImage"> </th>
<th scope="col"><spring:message code="manage.barrying.sac" /></br>
<sapn> & name</span></th>
<th scope="col"><spring:message code="manage.barrying.le.num" /></br> <span> & name</span></th>
<th scope="col"><spring:message code="manage.barrying.auto.rest.bar.flag" /></th>
</tr>
</thead>
<tbody>
<c:forEach items="${restricBarryindSACList}" var="searchResult"
varStatus="loop">
<c:choose>
<c:when test="${loop.index eq 0}">
<tr class="cellSelected">
<td><input type="radio" id="option${loop.index}"
value="${loop.index}" name="index" checked="checked" /></td>
</c:when>
<c:otherwise>
<tr>
<td><input type="radio" id="option${loop.index}"
value="${loop.index}" name="index" /></td>
</c:otherwise>
</c:choose>
<td><span class="SAC">${searchResult.salesAccountCode}</span></br>${searchResult.salesAccountName}
</td>
<td><span class="leNum">${searchResult.legalEntityNumber}</span></br>${searchResult.legalEntityName}
</td>
<c:choose>
<c:when test="${searchResult.thirdPartyBaringFlag eq 'N'}">
<td><span class="bar">Off</span></td>
</c:when>
<c:otherwise>
<td><span class="bar">On</span></td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>
</tbody>
</table>
<input type="hidden" id="bar" name="bar" value="" />
<input type="hidden" id="code" name="code" value="" />
<input type="hidden" id="leNum" name="leNum" value="" />
</div>
<hr>
<div id="apply">
<input type="submit" class="btn btn-default btnStyle floatRight" id="sacFields4ClickB" value="Apply Bar"/>
</div>
<div id="remove">
<input type="submit" class="btn btn-default btnStyle floatRight" id="sacFields5ClickB" value="Remove Bar"/>
</div>
</form:form>
</div>
以及上述表单的控制器如下:
@RequestMapping(value="/thirdPartyapplyRemoveBarryingforSac", method=RequestMethod.POST)
@CDBusinessProcess("AutoRestrictApplyRemoveBarr")
//@RequestParam(value="sac") String sac,@RequestParam(value="applyRemoveFlag") String applyRemoveFlag,@RequestParam("searchType") String searchType,
public ModelAndView thirdPartyapplyRemoveBarrying(@RequestParam(value="bar") String barFlag, @RequestParam(value="code") String sacCode,@RequestParam(value="leNum") String leNum,HttpServletRequest request) {
System.out.println("-----------------------Priting the requestParameterNames " + barFlag + " , " + sacCode +" , "+leNum);
System.out.println("#####################..................... Inside the controller method applyRemoveBarrying ....");
ApplyRemoveBarryingDTO newone = new ApplyRemoveBarryingDTO();
newone.setSacCode(sacCode);
newone.setLeCode(leNum);
newone.setRecordType(searchType);
newone.setAutoBarFlag(applyRemoveFlag);
System.out.println("#################........................... Calling the applyRemoveBarry method of the Service Class");
StoredProcedureResult result = restrictBarryingService.thirdPartyapplyRemoveBarry(newone,userId);
if(result.isSuccess())
{
modelAndView.addObject("isSuccess",true);
} else
{
modelAndView.addObject("isSuccess",false);
}
return modelAndView;
}
并且一旦执行了这个控制器,我想去第一个页面,它是autoRestrictSACSearchResult.jsp,它应该显示我在第一个表单中传递的值的更新结果,这个值是我用的jsp for search
<!-- sac search -->
which is written above.
答案 0 :(得分:1)
return new ModelAndView("redirect:/url");