0

嗨,我是 jsp 和 Spring 的新手。我有一张员工信息表。我想在每一行中添加一个编辑链接,然后单击一个编辑链接,它将将该行的主键发送到控制器。当我单击编辑链接时,它显示错误“客户端发送的请求在语法上不正确()。”

此页面显示表格

员工列表.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Employee List</title>
    </head>
    <body>
        <div align="center">
            <h1 align="center">Employee List</h1>
            <table align="center" border="1">
            <tr><th>Pk</th><th>Employee Name</th><th>Employee email</th><th>Address</th><th>Manager Id</th><th>Edit</th><th>Delete</th></tr>
            <c:forEach var="employeeList" items="${list}">
                <tr>
                    <td><c:out value="${employeeList.id}"/></td>
                    <td><c:out value="${employeeList.name}"/> </td>
                    <td><c:out value="${employeeList.email}"/> </td>
                    <td><c:out value="${employeeList.address}"/></td>
                    <td><c:out value="${employeeList.managerId}"/></td>

                    <td><a href="editEmployee.htm?id=${id}" >Edit</a></td>
                    <td><a href="deleteEmployee.htm?id=${id}" >Delete</a></td>
                </tr>
            </c:forEach>
            </table>
        </div>
    </body>
</html>

我的控制器代码是

@RequestMapping(value="/editEmployee.htm")
public String editEmployee(@RequestParam("id") int id,ModelMap model){
    try {
        Employee employee = employeeService.getEmployeeById(id);
        model.addAttribute("employee", employee);
        return "editEmployee";
    } catch (Exception ex) {
        return "index";
    }

}

编辑雇员.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Registration Page</title>
        <style>
            .error {
            color: #ff0000;
            font-style: italic;
            }
        </style>
    </head>
    <body>
        Edit Employee<br>
    </body>
</html>

我该如何解决这个问题。

4

2 回答 2

2

把你的jsp改成这样

<c:url var="editUrl" value="/editEmployee.htm" />
<a href="${editUrl}?id=${employeeList.id}">
    Edit
</a>
<c:url var="deleteUrl" value="/deleteEmployee.htm" />
<a href="${deleteUrl}?id=${employeeList.id}">
    Delete
</a
于 2012-07-05T08:32:18.540 回答
0

@RequestMapping(value="/editEmployee.htm") - 错误

@RequestMapping(value="/editEmployee/{id}")
public String editEmployee(@PathVariable int id,ModelMap model){
    try {
        Employee employee = employeeService.getEmployeeById(id);
        model.addAttribute("employee", employee);
        return "editEmployee";
    } catch (Exception ex) {
        return "index";
    }

}

还有一个 href="editEmployee.htm?id=${id} 这应该类似于 a href="editEmployee/${id}

于 2012-07-05T08:05:33.980 回答