我支持在Spring MVC和Sitemesh中开发的Web应用程序。我必须在应用程序的其中一个页面中添加分页功能。我正在使用N个记录第一次加载相同的页面,正如我在Hibernate中提到的MximumResults。但是当我单击Next按钮时,它表示不支持POST方法,并且支持的方法是GET。然后我将Controller和Form中的相应方法类型更改为GET。但后来说它不支持GET,支持的方法是POST。
我删除了Sitemesh配置本身,并尝试阅读SItemesh有时会产生问题虽然它不起作用。我尝试用SimpleHttpRequestHandler替换<mvc:resources>
配置,尽管没有快乐。
请参阅相应的JSP,Controller,Spring Configuration和附带的web.xml。
触发页面
<form:form id="form-${eta.paymentPeriod.period}" method="post" modelAttribute="etaForm" action="${pageContext.request.contextPath}/performance/searchPeriodSpecificETADetails.htm">
<tr>
<input name="courierId" type="hidden" value="<c:out value="${etaDetails.courierId}"/>"/>
<input name="year" type="hidden" value="<c:out value="${eta.paymentPeriod.year}"/>"/>
<input name="period" type="hidden" value="<c:out value="${eta.paymentPeriod.period}"/>"/>
<input name="timeslot" type="hidden" value="<c:out value="${eta.timeSlot}"/>"/>
<input name="daysPassed" type="hidden" value="<c:out value="${eta.daysPassed}"/>"/>
<input name="percentage" type="hidden" value="<c:out value="${eta.percentage}"/>"/>
<td style="padding-left:10px; color:blue;">
<button type="submit" class="link"><span><c:out value="P${eta.paymentPeriod.period}"/></span></button>
<%-- <a href="#" id="<c:out value="${eta.paymentPeriod.period}"/>" class="empty"> ${eta.paymentPeriod.period} </a> --%>
</td>
<td style="padding-left:40px"> <c:out value="${eta.timeSlot}"/> </td>
<td style="padding-left:20px"> <c:out value="${eta.percentage}"/> </td>
<td style="padding-left:30px"> <c:out value="${eta.daysPassed}"/> </td>
<td style="padding-left:30px"> <c:out value="${eta.daysFailed}"/> </td>
</tr>
</form:form>
分页JSP
<c:forEach var="eta" items="${etaDaySpecificDetails}">
<form:form method="post" modelAttribute="etaForm" action="${pageContext.request.contextPath}/performance/searchPeriodSpecificETAFailureDetails.htm">
<tr>
<c:set var="failed" value="${eta.set - eta.passed}"/>
<c:if test="${eta.passed == eta.set}">
<fmt:formatNumber value="100" var="success" maxFractionDigits="1"/>
</c:if>
<c:if test="${eta.passed != eta.set}">
<fmt:formatNumber value="${(eta.passed / eta.set)*100}" var="success" maxFractionDigits="1"/>
</c:if>
<fmt:formatDate value="${eta.date}" var="etaDate" pattern="E d MMM" />
<input name="year" type="hidden" value="<c:out value="${etaSummery.year}"/>"/>
<input name="period" type="hidden" value="<c:out value="${etaSummery.period}"/>"/>
<input name="timeslot" type="hidden" value="<c:out value="${etaSummery.timeslot}"/>"/>
<input name="courierId" type="hidden" value="<c:out value="${etaSummery.courierId}"/>"/>
<input name="dateId" type="hidden" value="<c:out value="${eta.dateId}"/>"/>
<input name="date" type="hidden" value="<c:out value="${eta.date}"/>"/>
<input name="daysPassed" type="hidden" value="<c:out value="${etaSummery.daysPassed}"/>"/>
<input name="percentage" type="hidden" value="<c:out value="${etaSummery.percentage}"/>"/>
<td style="padding-left: 10px; color: blue;"><c:out value="${etaDate}" /></td>
<td style="padding-left: 10px"><c:out value="${eta.set}" /></td>
<td style="padding-left: 20px"><c:out value="${eta.modified}" /></td>
<td style="padding-left: 30px"><c:out value="${eta.cancelled}" /></td>
<td style="padding-left: 30px"><c:out value="${eta.passed}" /></td>
<c:if test="${failed > 0}">
<td style="padding-left:30px;">
<button type="submit" id="failure_link_${eta.dateId}" class="link" style="color:red;text-decoration: underline;"><span><c:out value="${failed}"/></span></button>
</td>
</c:if>
<c:if test="${failed == 0}">
<td style="padding-left: 30px"><c:out value="${failed}" /></td>
</c:if>
<td style="padding-left: 15px"><c:out value="${success}" /> %</td>
</tr>
</form:form>
</c:forEach>
</table>
<form:form id="form-next" method="POST" modelAttribute="etaForm" action="${pageContext.request.contextPath}/performance/searchPeriodSpecificETADetailsNextRecord.htm">
<input name="year" type="hidden" value="<c:out value="${etaSummery.year}"/>"/>
<input name="period" type="hidden" value="<c:out value="${etaSummery.period}"/>"/>
<input name="timeslot" type="hidden" value="<c:out value="${etaSummery.timeslot}"/>"/>
<input name="courierId" type="hidden" value="<c:out value="${etaSummery.courierId}"/>"/>
<input name="paginationMetaInfo" type="hidden" value="<c:out value="${etaSummery.paginationMetaInfo}"/>"/>
<td style="padding-left:10px; color:blue;">
<button type="submit" class="link"><span>Next</span></button>
<%-- <a href="#" id="<c:out value="${eta.paymentPeriod.period}"/>" class="empty"> ${eta.paymentPeriod.period} </a> --%>
</form:form>
**控制器**
@Controller
@SessionAttributes("courierDetails")
@RequestMapping("performance")
public class CourierPerformanceController {
private CourierPerformanceManager courierPerformanceManager;
@Autowired
private MessageSource messages;
private MyPerformanceManager myPerformanceManager;
private BeanPropertyCopier beanPropertyCopier;
@Value("${info.myperformance.depot.secondTarget}")
private Double depoSecondTarget;
@Value("${info.myperformance.delivery.secondTarget}")
private Double deliverySecondTarget;
@Value("${info.myperformance.collection.secondTarget}")
private Double collectionSecondTarget;
private static final String DOZ_ETA_VO_TO = "etaVOToEtaTo";
private static final String ATTR_ETA_DAY_SPECIFIC_DETAILS = "etaDaySpecificDetails";
private static final String ATTR_ETA_DAY_SPECIFIC_FAILURE_DETAILS = "etaDaySpecificFailureDetails";
private static final String ATTR_ETA_SUMMERY = "etaSummery";
private static final String ATTR_ETA_DETAILS = "etaDetails";
private static final String DATA_TYPE_JSON = "application/json";
@Autowired
public CourierPerformanceController(MyPerformanceManager myPerformanceManager,CourierPerformanceManager courierPerformanceManager,
BeanPropertyCopier beanPropertyCopier) {
this.myPerformanceManager = myPerformanceManager;
this.courierPerformanceManager = courierPerformanceManager;
this.beanPropertyCopier = beanPropertyCopier;
}
private DataTables buildDataTables(CourierDetails courierDetails) throws CouriersException {
MyPerformanceResults results = myPerformanceManager.getPerformanceDetails(courierDetails.getCrId());
return CourierPerformanceGraphUtil.createAndInitializeDataTableWithCourierPerformanceDetails(results, messages);
}
@RequestMapping(
value = {
WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_SEARCH_ENQUIRY_PEFORMANCE_DETAILS,
WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_SEARCH_COLLECTION_PEFORMANCE_DETAILS,
WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_SEARCH_RECEIPT_PEFORMANCE_DETAILS,
WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_SEARCH_DELIVERY_PEFORMANCE_DETAILS},
method = RequestMethod.GET, produces = DATA_TYPE_JSON)
public @ResponseBody DataTables searchCourierEnquiryPerformanceDetails(@ModelAttribute CourierDetails courierDetails, HttpServletRequest session)
throws CouriersException {
DataTables dataTables = buildDataTables(courierDetails );
return dataTables;
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_ETA_DETAILS_FOR_PRIMARY_TAB, method = RequestMethod.GET)
public ModelAndView searchCourierETAPerformanceDetailsForPrimaryTab(@ModelAttribute CourierDetails courierDetails,Model model, HttpServletRequest session)
throws CouriersException {
ETASearchCriteria searchCriteria = new ETASearchCriteria();
searchCriteria.setCourierId(courierDetails.getCrId());
resetPaginationMetaInfo();
final ETADetails etaDetails = courierPerformanceManager.searchETAForAllAvailablePeriods(searchCriteria);
return new ModelAndView(SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ETA_PERFORMANCE_DETAILS, ATTR_ETA_DETAILS , etaDetails);
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_DELIVERY_PEFORMANCE_DETAILS, method = RequestMethod.GET)
public ModelAndView redirectToCourierDeliveryDetails(@ModelAttribute CourierDetails courierDetails, HttpServletRequest session)
throws CouriersException {
return new ModelAndView(SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ETA_DELIVERY_DETAILS);
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_RECEIPT_PEFORMANCE_DETAILS, method = RequestMethod.GET)
public ModelAndView redirectToCourierReceiptDetails(@ModelAttribute CourierDetails courierDetails, HttpServletRequest session)
throws CouriersException {
return new ModelAndView(SPRING_VIEW_URL.COUR_PERF_CONTROLLER_MYPERFORMANCE);
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_COLLECTION_PEFORMANCE_DETAILS, method = RequestMethod.GET)
public ModelAndView redirectToCourierCollectionDetails(@ModelAttribute CourierDetails courierDetails, HttpServletRequest session)
throws CouriersException {
return new ModelAndView(SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_COLLECTION_DETAILS);
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_GET_ENQUIERY_PEFORMANCE_DETAILS, method = RequestMethod.GET)
public ModelAndView redirectToCourierEnquiryDetails(@ModelAttribute CourierDetails courierDetails, HttpServletRequest session)
throws CouriersException {
return new ModelAndView(SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ENQUIRY_DETAILS);
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_POST_SERACH_PERIOD_SPECIFIC_ETA_DETAILS, method = RequestMethod.POST)
public String searchPeriodSpecificETADetails(@ModelAttribute CourierDetails courierDetails,@ModelAttribute("etaForm")
ETAValueObject etaValueObject , Model model,
HttpServletRequest session) throws CouriersException {
List<DaySpecificETAInformation> etaDetails = searchETADetailsForSpecificPeriod(etaValueObject);
model.addAttribute(ATTR_ETA_DAY_SPECIFIC_DETAILS, etaDetails);
model.addAttribute(ATTR_ETA_SUMMERY, etaValueObject);
return SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ETA_DAY_SPECIFIC_PERF_DETAILS;
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_POST_SERACH_PERIOD_SPECIFIC_ETA_DETAILS_NEXT_RECORD, method = RequestMethod.POST)
public String searchPeriodSpecificETADetailsNextRecord(@ModelAttribute CourierDetails courierDetails,@ModelAttribute("etaForm")
ETAValueObject etaValueObject , Model model,
HttpServletRequest session) throws CouriersException {
List<DaySpecificETAInformation> etaDetails = searchETADetailsForSpecificPeriod(etaValueObject);
model.addAttribute(ATTR_ETA_DAY_SPECIFIC_DETAILS, etaDetails);
model.addAttribute(ATTR_ETA_SUMMERY, etaValueObject);
return SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ETA_DAY_SPECIFIC_PERF_DETAILS;
}
@RequestMapping(
value = WEB_REQUEST_URL.COUR_PERF_CONTROLLER_HTTP_POST_SERACH_PERIOD_SPECIFIC_ETA_FAIL_DETAILS, method = RequestMethod.POST)
public String searchDaySpecificETAFailureInformation(@ModelAttribute CourierDetails courierDetails,@ModelAttribute
ETAValueObject etaValueObject , Model model,
HttpServletRequest session) throws CouriersException {
List<DaySpecificETAFailureInformation> etaDetails = searchDaySpecificETAFailureInformation(etaValueObject);
model.addAttribute(ATTR_ETA_DAY_SPECIFIC_FAILURE_DETAILS, etaDetails);
model.addAttribute(ATTR_ETA_SUMMERY, etaValueObject);
return SPRING_VIEW_URL.COUR_PERF_CONTROLLER_COURIER_ETA_DAY_SPECIFIC_FAIL_DETAILS;
}
private List<DaySpecificETAInformation> searchETADetailsForSpecificPeriod(ETAValueObject etaValueObject) {
ETASearchCriteria searchCriteria = copyDetailsFromSourceToDestination(etaValueObject, ETASearchCriteria.class, DOZ_ETA_VO_TO);
availSearchResultsCountForETADetailsForSpecificPeriod(searchCriteria,etaValueObject);
List<DaySpecificETAInformation> etaDetails = courierPerformanceManager.searchETADetailsForSpecificPeriod(searchCriteria);
return etaDetails;
}
private void availSearchResultsCountForETADetailsForSpecificPeriod(ETASearchCriteria searchCriteria,ETAValueObject etaValueObject) {
PaginationMetaInfo paginationMetaInfoFromView = etaValueObject.getPaginationMetaInfo();
if(paginationMetaInfoFromView == null) {
paginationMetaInfoFromView = PaginationMetaInfo.getPaginationMetaInfo();
Integer maximumResults = courierPerformanceManager.findSearchResultsCountForETAFailureDetailsForSpecificDateAndPeriod(searchCriteria);
paginationMetaInfoFromView.setMaximumResults(maximumResults);
etaValueObject.setPaginationMetaInfo(paginationMetaInfoFromView);
}
PaginationMetaInfo.addPaginationMetaInfo(paginationMetaInfoFromView);
paginationMetaInfoFromView.updateNextRowIndex();
}
private void resetPaginationMetaInfo() {
PaginationMetaInfo.addPaginationMetaInfo(new PaginationMetaInfo());
PaginationMetaInfo.getPaginationMetaInfo().setNextRowIndex(0);
}
private List<DaySpecificETAFailureInformation> searchDaySpecificETAFailureInformation(ETAValueObject etaValueObject) {
ETASearchCriteria searchCriteria = copyDetailsFromSourceToDestination(etaValueObject, ETASearchCriteria.class, DOZ_ETA_VO_TO);
List<DaySpecificETAFailureInformation> etaDetails = courierPerformanceManager.searchETAFailureDetailsForSpecificDateAndPeriod(searchCriteria);
return etaDetails;
}
private <T> T copyDetailsFromSourceToDestination(Object src, Class<T> clazz, String mappingName) {
return beanPropertyCopier.copyDetailsFromSourceToDestination(src, clazz, mappingName);
}
}
我正在点击第一页的searchPeriodSpecificETADetails和searchPeriodSpecificETADetailsNextRecord来获取分页结果。
static String COUR_PERF_CONTROLLER_HTTP_POST_SERACH_PERIOD_SPECIFIC_ETA_DETAILS = "/searchPeriodSpecificETADetails";
static String COUR_PERF_CONTROLLER_HTTP_POST_SERACH_PERIOD_SPECIFIC_ETA_DETAILS_NEXT_RECORD = "/searchPeriodSpecificETADetailsNextRecord.htm";
弹簧配置
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/img/**" location="/images/" />
<mvc:resources mapping="/fonts/**" location="/fonts/" />
<mvc:resources mapping="/js/**" location="/js/" />
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
Web.xml中
<filter>
<filter-name>sitemeshGeneralFilter</filter-name>
<filter-class>uk.co.hermes.filters.SitemeshGeneralFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemeshGeneralFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Sitemesh过滤器
public class SitemeshGeneralFilter extends ConfigurableSiteMeshFilter {
private final Logger LOG = Logger.getLogger(SitemeshGeneralFilter.class);
public SitemeshGeneralFilter() {
super();
}
/**
* See http://wiki.sitemesh.org/display/sitemesh3/Configuring+SiteMesh+3
*/
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// apply this decorator (template) to the path defined...
builder.addDecoratorPath("/*", "/WEB-INF/jsp/sitemeshDecorators/generalDecorator.jsp")
// ... when the response type matches one of these
.setMimeTypes("text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml");``
}}
如果有人可以帮助我,真的很棒。