Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html JSP-如何组合过滤器和分页?_Html_Jsp_Spring Mvc - Fatal编程技术网

Html JSP-如何组合过滤器和分页?

Html JSP-如何组合过滤器和分页?,html,jsp,spring-mvc,Html,Jsp,Spring Mvc,我正在用Spring开发一个应用程序,我一直在尝试在我的页面中组合过滤器和分页 独立地,我的过滤器和分页工作正常,我能够更改页面和过滤我的团队列表 我的问题发生在我应用过滤器然后尝试更改页面时。我的过滤器会自动重置 当我单击href链接时,是否有办法保留表单信息 我还尝试为每个页码添加一个“提交按钮”,但没有成功 实现此解决方案的最佳方式是什么 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@

我正在用Spring开发一个应用程序,我一直在尝试在我的页面中组合过滤器和分页

独立地,我的过滤器和分页工作正常,我能够更改页面和过滤我的团队列表

我的问题发生在我应用过滤器然后尝试更改页面时。我的过滤器会自动重置

当我单击
href
链接时,是否有办法保留
表单
信息

我还尝试为每个页码添加一个“提交按钮”,但没有成功

实现此解决方案的最佳方式是什么

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<?xml version="1.0" encoding="ISO-8859-1" ?>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>List of teams</title>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/lista.css"/>
    </head>
    <body>
        <h1>List of teams</h1>
        <p>Here you can see the list of the teams, edit them, remove or update.</p>

        <form:form method="POST" action="/SpringMVCTeams/team/list">
            <table>
                <tr>
                    <td><label>Country</label></td>
                    <td>
                        <form:select path="country">
                            <form:option value="default-value" label="--Please Select" />
                            <form:options items="${countryList}" itemValue="idCountry" itemLabel="name" />
                        </form:select>          
                    </td>
                    <td><form:errors path="country" cssClass="error" /></td>
                </tr>
                <tr>
                    <td><label>Division</label></td>
                    <td>
                        <form:select path="division">
                            <form:option value="default-value" label="--Please Select" />
                            <form:options items="${divisionList}" itemValue="idDivision" itemLabel="name" />
                        </form:select>          
                    </td>
                    <td><form:errors path="division" cssClass="error" /></td>
                </tr>     
                <tr>
                    <td colspan="2">
                        <input type="submit" value="Submit"/>
                    </td>
                </tr>
            </table>

            <c:forEach begin="1" end="${paginationProducts}" var="p">
                <a href="/SpringMVCTeams/team/list/${p}">${p}</a>
            </c:forEach>


        </form:form>

        <table border="1px" cellpadding="0" cellspacing="0" >
            <thead>
                <tr>
                    <th width="10%">id</th>
                    <th width="15%">name</th>
                    <th width="10%">rating</th>
                    <th width="10%">actions</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach var="team" items="${teams}">
                <tr>
                    <td>${team.id}</td>
                    <td>${team.name}</td>
                    <td>${team.rating}</td>
                    <td>
                    <a href="${pageContext.request.contextPath}/team/edit/${team.id}.html">Edit</a><br/>
                    <a href="${pageContext.request.contextPath}/team/delete/${team.id}.html">Delete</a><br/>
                    </td>
                </tr>
                </c:forEach>
            </tbody>
        </table>

        <p><a href="${pageContext.request.contextPath}/index.html">Home page</a></p>

    </body>
</html>

小组名单
小组名单
在这里,您可以查看团队列表、编辑、删除或更新

国家 分部 身份证件 名称 评级 行动 ${team.id} ${team.name} ${team.rating}

我设法做到了

我添加了按钮来提交不同的
信息。然后,在控制器中,我验证了参数
action
的值

JSP页面:

    <form:form method="POST" action="/SpringMVCTeams/team/list">
        <table>
            <tr>
                <td><label>Country</label></td>
                    <td>
                    <form:select path="country">
                        <form:option value="default-value" label="--Please Select" />
                        <form:options items="${countryList}" itemValue="idCountry" itemLabel="name" />
                    </form:select>          
                </td>
                    <td><form:errors path="country" cssClass="error" /></td>
            </tr>
            <tr>
                <td><label>Division</label></td>
                <td>
                    <form:select path="division">
                        <form:option value="default-value" label="--Please Select" />
                        <form:options items="${divisionList}" itemValue="idDivision" itemLabel="name" />
                    </form:select>          
                </td>
                <td><form:errors path="division" cssClass="error" /></td>
            </tr>     
            <tr>
                <td colspan="2">
                    <button type="submit" name="action" value="1" class="btn-link">Submit</button>
                </td>
            </tr>
        </table>

        <c:forEach begin="1" end="${paginationProducts}" var="p">
                <button type="submit" name="action" value="${p}" class="btn-link">${p}</button>
            </c:forEach>

    </form:form>
    @RequestMapping(value="/list" , method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView listOfTeams(HttpServletRequest request, TeamList teamList) {
    String action= request.getParameter("action");

    if(action == null)
        return getlistOfTeams(teamList, 1);
    else
        return getlistOfTeams(teamList, Integer.parseInt(action));
}
有人能提出更好的解决方案吗