在spring mvc中传递两个JSP之间的参数

时间:2017-12-08 08:04:56

标签: java spring jsp spring-mvc

我在两个jsp之间传输数据时遇到问题 有两个控制器,其中第一个接受输入数据,第二个使用此参数生成行

第一个控制器组接收两个参数

    @RequestMapping(value = "/create", method = RequestMethod.POST)
  public String ProjectSizePost(
      @RequestParam("countSprints") Integer countSprints,
      @RequestParam("countWorkers") Integer countWorkers) {
BigInteger a = BigInteger.valueOf(countSprints);

    return "project/project_size";
  }

  @RequestMapping(value = "/create", method = RequestMethod.GET)
  public String projectSizeGet() {

    return "project/project_size";
  }

他的jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Size</title>
</head>
<body>
    <%--<c:forEach var="inputLine" begin="1" end="4">
            <td><input type="text" name="projectManagerId" size="70" value={count} ></td><br>
    </c:forEach>--%>
    <form action="/project/show_size" method="post" name="/project/show_size"
          commandName="projectSizeForm">
    <tr>
        <td>Count of sprints:</td>
        <td><input type="text" name="countSprints" size="70" value = ${countSprints}  ></td>
    </tr> <br>
    <tr>
        <td>Count of workers:</td>
        <td><input type="text" name="countWorkers" size="70" value = ${countWorkers}  ></td>
    </tr>

        <tr>
            <input type="submit" value="Next page"/></td>
        </tr>
    </form>

</body>
</html>

第二个控制器和jsp必须从第一个jsp

获取参数
@RequestMapping(value = "/create", method = RequestMethod.POST)
  public String createProject(
      @RequestParam("projectId") Integer id,
      @RequestParam("name") String name,
      @RequestParam("startDate") String startDate,
      @RequestParam("endDate") String endDate,
      @RequestParam("projectStatus") OCStatus projectStatus,
      @RequestParam("projectManagerId") Integer projectManagerId) {
    MapperDateConverter mdc = new MapperDateConverter();
   *//*Project project = new Project.ProjectBuilder()
        .projectId(BigInteger.valueOf(id))
        .name(name)
        .startDate(mdc.convertStringToDate(startDate))
        .endDate(mdc.convertStringToDate(endDate))
        .build();
    project.setProjectStatus(projectStatus);
    project.setProjectManagerId(BigInteger.valueOf(projectManagerId));*//*
    //projectDao.createProject(project);
    return "project/create";
  }

第二个jsp:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Registration</title>
</head>
<body>
<div align="center">
    <form action="/project/create" method="post" name="/project/create"
               commandName="projectForm">
        <table border="0">
            <tr>
                <h2>CreateProject</h2></td>
            </tr>
            <tr>
                <td>Project Id:</td>
                <td><input type="text" name="projectId" size="70" value = ${projectId} ></td>
            </tr>
            <tr>
                <td>Project Name:</td>
                <td><input type="text" name="name" size="70" value = ${projectName} ></td>
            </tr>
            <tr>
                <td>StartDate (mm/dd/yyyy):</td>
                <td><input type="text" name="startDate" size="70" value = ${startDate} ></td>
            </tr>
            <tr>
                <td>EndDate (mm/dd/yyyy):</td>
                <td><input type="text" name="endDate" size="70" value = ${endDate}  ></td>
            </tr>
            <tr>
                <td>Status:</td>
                <td><input type="text" name="projectStatus" size="70" value = ${status}  ></td>
            </tr>
            <tr>
                <td>Project Manager:</td>
                <td><input type="text" name="projectManagerId" size="70" value = ${pmId}  ></td>
            </tr>
            <tr>
                <td>Count of sprints</td>
                <td><input type="text" name="countSprints" size="70" value = ${countSprints}  ></td>
            </tr>
            <tr>
                <td>Count of sprints</td>
                <td><input type="text" name="countWorkers" size="70" value = ${countWorkers}  ></td>
            </tr>
            <tr>
                <input type="submit" value="Create"/></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>

Params countSprints countWorkers

0 个答案:

没有答案