繁体   English   中英

单击按钮,将Arraylist的特定对象从JSP发送到Servlet

[英]Send particular object of Arraylist from JSP to Servlet on click of button

在这里,我将从此JSP向Servlet发送联系号码。 单击按钮后,我要发送与该特定按钮关联的“联系电话”。 我不知道该怎么做,请提出一种方法...此外,表格边框未显示,我尝试增加宽度和厚度仍未显示。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">
<title>View Employee</title>
<style>
td
{
 padding: 12px 20px;
    margin: 8px 0;
}
th
{
 padding: 12px 20px;
    margin: 8px 0;
}
</style>
</head>




<body style="background-color:powderblue;">


<%@ include file="MenuBar.jsp" %>



<%@ page import="in.idk.service.ViewEmployee" %> 
<%@ page import="java.util.List" %>
<%@ page import= "in.idk.model.Employee" %>
<table>
<tr>
<th width="119"><label>Employee_Name</label></th>
<th width="168"><label>Employee_Contact_No.</label></th>
<th><label></label></th>
</tr>

<%
                     ViewEmployee viewEmployee = new ViewEmployee();
                     List<Employee> list = viewEmployee.getListOfEmployees();

                             for (Employee e : list) {
                 %>
                 <tr>
                     <td width="119"><%=e.getEmployeeName()%></td>
                     <td width="168"><%=e.getEmployeeContactNo()%></td>

                     <td><form action="GetOneEmployee" method="post">

                    <input type="submit" value="Submit" ></form></td>

                 </tr>
                 <%}%>

</table>

</body>
</html>

在内部表单中,将员工引用分配给隐藏类型的输入,并为该属性命名

<input name="emp" value="<%=e%>" type="hidden">

基于emp id从数据库检索数据

在servlet中,从请求对象引用中读取该参数

对于表格边框,请在表格开头标签中使用border属性

<table border="1">

点击“提交”按钮后,您将向服务器发送请求。

您可以使用以下请求对象访问请求参数

request.getParameter("parameter name");

如果您要访问客户联系电话,请先为其分配一个名称,然后如上所述在servlet中对其进行访问。

谢谢,迁移鸽和jangachary sriramadasu都回答了我的问题。 这是我的问题的答案。

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">
<title>View Employee</title>
<style>
td
{
 padding: 12px 20px;
    margin: 8px 0;
}
th
{
 padding: 12px 20px;
    margin: 8px 0;
}
</style>
</head>

<body style="background-color:powderblue;">
<%@ include file="MenuBar.jsp" %>
<%@ page import="in.idk.service.ViewEmployee" %> 
<%@ page import="java.util.List" %>
<%@ page import= "in.idk.model.Employee" %>
<table border="1">
<tr>
<th width="119"><label>Employee_Name</label></th>
<th width="168"><label>Employee_Contact_No.</label></th>
<th><label></label></th>
</tr>

<%
                     ViewEmployee viewEmployee = new ViewEmployee();
                     List<Employee> list = viewEmployee.getListOfEmployees();

                             for (Employee e : list) {
                 %>
                 <tr>
                     <td ><%=e.getEmployeeName()%></td>
                     <td ><%=e.getEmployeeContactNo()%></td>

                     <td><a name="view" href="GetOneEmployee?id=<%=e.getId() %>">View</a></td>

                 </tr>
                 <%}%>




</table>
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM