2017-04-20 108 views
0

在这里,我从这个JSP发送联系号码到Servlet。点击一个按钮后,我想发送与该特定按钮关联的联系人号码。我不知道该怎么做,请建议一种方式... 另外,表格边框不显示我试图增加宽度和厚度,但它仍然不显示。发送Arraylist从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> 

回答

0

谢谢,迁徙鸽和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> 
0

内部形式分配雇员参考类型隐藏的一个输入端和提供一个名称该属性

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

基于EMP ID从数据库取回

在小服务程序读取该参数数据请求对象引用

并且对于表格边框在表格中使用边界属性标记

<table border="1"> 
0

一旦你点击“提交”按钮,你就发送一个请求到服务器。

,您可以访问请求对象的请求参数如下

request.getParameter("parameter name"); 

你的情况首先访问客户联系人号码指定一个名称,然后如上所述访问它的servlet。