我很难根据参数传递显示数据。下面是我的基于序列的代码。我的问题是,什么时候调试,它传递给第二页jsp的控制器,它检索的参数是courseId,但是当它不显示jsp和控制器中的数据时获取数据..我知道我的问题很长,但请帮助我。第一页将显示可用课程列表。当用户点击课程时,它将进入控制器
@RequestMapping(value="MregisteredClassesDetail.phone")
public final ModelAndView registeredClassesDetail(final HttpServletRequest request,
final HttpServletResponse response,HttpSession session) {
ModelAndView mav = new ModelAndView();
log.debug("Registered Classes Detail:");
log.debug("CourseId:"+request.getParameter("courseId"));
request.setAttribute("page", AlteraCommonConstant.DEFAULT_PAGE);
request.setAttribute("row", AlteraCommonConstant.DEFAULT_PAGE_SIZE);
request.setAttribute("courseId","courseId");
System.out.println(">>>>>>>>>>>>>>>> Registered Classes Detail");
mav.setViewName("mobile/MregisteredClassesDetail.jsp");
return mav;
}
然后它将转到jsp第二页..
$('#MregisteredClassesDetails').live('pageshow', function(){
var rowInput = "1";
var pageInput = "1";
var idInput = document.getElementById("courseId");
$.ajax({
url: '${pageContext.request.contextPath}/getRegisteredClassesDetails.html',
data: ( {rows : rowInput , page : pageInput, courseId : idInput}),
type: 'POST',
success: function(json_results){
$('#list').append('<ul data-role="listview" data-inset="true"</ul>');
listItems = $('#list').find('ul');
html = '#################################################################################################';
html += '<h1>' +json_results.courseName+'</h1>';
html += '#################################################################################################';
html += '<br> Registration # : '+json_results.regNo+'</br>';
html += '<br> Status : '+json_results.regStatus+'</br>';
html += '<br> Location : '+json_results.courseLoc+'</br>';
html += '<br> Start Date : '+json_results.startDate+'</br>';
html += '<br> Registered Person : '+json_results.fullName+'</br>';
html += '<br> Rate : '+json_results.rate+'</br>';
listItems.append(html);
$('#list ul').listview();
$.mobile.pageLoading(true);
}
});
});
和html
<form name="ViewClassForm" method="POST">
<input name="courseId" type="hidden" value="${MregisteredClassesDetail.courseId}"/>
</form>
<div data-role="page" id="MregisteredClassesDetails" data-add-back-btn="true">
<div data-role="header" data-position="fixed" data-theme="b"><h1></h1>
</div><!-- /header -->
<div data-role="content">
<div id="courseDetail">
<ul data-role="listview" data-inset="true" id="list"></ul>
</div>
</div><!-- /content -->
然后它将返回控制器以检索数据..
@RequestMapping(value = "getRegisteredClassesDetails.html", method = RequestMethod.POST)
public @ResponseBody CustomPagedResultResponse getRegisteredClassesDetails(
HttpServletRequest request,HttpSession session) {
CustomPagedResultResponse paging = new CustomPagedResultResponse();
log.debug("getRegisteredClassesData.html:");
log.debug("rows:"+request.getParameter("rows"));
log.debug("courseId:"+request.getParameter("courseId"));
log.debug("page:"+request.getParameter("page"));
log.debug("sidx:"+request.getParameter("sidx"));
log.debug("sord:"+request.getParameter("sord"));
String page = request.getParameter("page");
int pageSize = new Integer(request.getParameter("rows")).intValue();
StringBuffer condition = new StringBuffer();
if (request.getParameter("sidx") != null && !request.getParameter("sidx").equals("")) {
condition.append(request.getParameter("sidx"));
condition.append(" ");
}
if (request.getParameter("sord") != null && !request.getParameter("sord").equals("")) {
condition.append(request.getParameter("sord"));
}
log.debug("condition: " + condition.toString());
log.debug("page:"+page);
log.debug("row:"+pageSize);
String courseType = "%";
UserProfile userProfile = (UserProfile)session.getAttribute("userProfile");
//////////////////////////////////////////////////////
// Retrieve Total Record first
///////////////////////////////////////////////////////
RegisteredClassesSearch search = new RegisteredClassesSearch();
search.setLanguage("ENU");
search.setLoginRowId(userProfile.getContactRowId());
search.setRegNo(null);
search.setAction("1");
search.setCourseType(courseType);
search.setPage(null);
search.setPageSize(null);
search.setOrderBy(null);
Integer recordCount = registeredClassesService.getTotalAccounts(search);
log.debug("*****Training Controller Total record:"+recordCount);
System.out.println("*****Training Controller Total record:"+recordCount);
//////////////////////////////////////////////////////
// Retrieve Total Record first
///////////////////////////////////////////////////////
if(recordCount>0){
System.out.println("******** Login Id:"+userProfile.getContactRowId());
System.out.println("******** Course Type:"+courseType);
System.out.println("******** Page Size:"+pageSize);
System.out.println("******** Page:"+page);
System.out.println("******** Order By:"+condition);
List<RegisteredClassesTest> registeredClassesView = registeredClassesService.getAccounts(search);
paging.setRows(registeredClassesView);
}else{
paging.setRows(null);
}
paging.setRecords(String.valueOf(recordCount));
paging.setPage(page);
int total = recordCount % pageSize == 0 ? recordCount / pageSize : recordCount / pageSize + 1;
paging.setTotal(String.valueOf(total));
return paging;
}
答案 0 :(得分:0)
我认为在这种情况下你有一个拼写错误。
在您的第一个控制器中,您将在请求参数中设置课程ID,如下所示。
request.setAttribute("courseId","courseId");
据我说它应该是
request.setAttribute("courseId",some int value);
您没有在 courseId 中添加一些实际值。
希望这会对你有所帮助。
干杯。