如何在JSP页面上同时执行UPDATE和DELETE操作?

时间:2016-06-02 06:52:54

标签: java spring jsp servlets

我想执行多个操作,如DELETE和UPDATE这样做我需要将数据发送到Controller, 我在做错误的地方?

以下是我的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" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="TimeDetailBean" class="com.logic.bean.userBean"   scope="application" />
<!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>Manage Results</title>

</head>
<body>
<center>
<h1>The Employee_Info Results </h1>

<table>
<tr><th>Name</th><th>Last name</th><th>Password</th></tr>
<c:forEach items="${rows}" var="row">
<tr>
<td><input type="text" name="name" value=${row.NAME}></td>
<td><input type="text" name="lastname" value=${row.LASTNAME}></td>
<td><input type="text" name="password" value=${row.PASSWORD}></td>
<td><a href="update.do">UPDATE</a></td>
<td><a href="delete.do">DELETE</a></td>
</tr>

</c:forEach>
</table>

</center>
</body>
</html>

及以下是我想要的控制器名称,姓氏和密码的值

@RequestMapping("/delete")
    public ModelAndView Delete(HttpServletRequest request, HttpServletResponse response)
    {
        System.out.println("Delete Controller Executed");
        userBean ub= new userBean();
        Dao d= new Dao();
        String name=request.getParameter("name");
        String lastname=request.getParameter("lastname");

        System.out.println("Name catch"+name);
        System.out.println("Lastname catch"+lastname);



        return new ModelAndView("deleteSuccess");

    }//delete ends

提前致谢。 。

1 个答案:

答案 0 :(得分:0)

为了将数据从JSP发送到Controller

  1. 使用操作(/ delete)和method = POST
  2. 创建表单
  3. 使用指向表单操作的@RequestMapping(“/ delete”)创建一个Controller
  4. 在Controller中使用Request.getParameter(“name”)。
  5. 现在,JSP Spring Servlet Dispatcher中的提交按钮将是Controller类中的映射表单,并将数据从JSP发送到控制器。

    如果需要更多信息,请告诉我们,我将分享示例示例

    此致 帕