将数据从jsp从html表传递到servlet

将数据从jsp从html表传递到servlet,html,jsp,session,servlets,Html,Jsp,Session,Servlets,我正在使用JSP和servlet开发一个web应用程序。 在那个应用程序中,我必须在html表中显示来自数据库表stud(studID、name、add)的数据,表中的每一行在最后一列都有一个与其关联的超链接。在点击超链接后,我想从表中获取(studID) 到目前为止,我已经完成了从数据库中获取数据,然后将其放入列中,然后为每行添加超链接。。但我无法从与hyperlink关联的html表中获取(studID) 提前谢谢 源代码: <% String[][] data = (String[

我正在使用JSP和servlet开发一个web应用程序。 在那个应用程序中,我必须在html表中显示来自数据库表stud(studID、name、add)的数据,表中的每一行在最后一列都有一个与其关联的超链接。在点击超链接后,我想从表中获取(studID)

到目前为止,我已经完成了从数据库中获取数据,然后将其放入列中,然后为每行添加超链接。。但我无法从与hyperlink关联的html表中获取(studID)

提前谢谢

源代码:

<% 
String[][] data = (String[][])request.getAttribute("data"); 
String[] cNames = (String[])request.getAttribute("columnNames"); 
//headings 
%> 
<table> 
<tr> 
<% 
for(int i=0;i<cNames.length;i++) { 
%> 
<th>
<%= cNames[i] %>
</th>
<% 
} 

//data if(data!=null) 
for(int i=0;i<data.length;i++) { 
%>
<tr> 
<% 
for(int a=0;a<3;a++) {
%> 
<td>
<%= 
data[i][a] 
%>
</td> 
<% 
//hyperlink 
if(a==2) { 
%> 
<td>
<a href="PlanProtocol" id=<%=i%> onclick="<% session.setAttribute("ID","p2"); %>" >Edit</a></td> 
<% 
} 
} 
%>
</tr> 
<% } %> 
<tr>
</table>


我认为应该在JSP中提取studID,并将studID格式化为URL html页面的查询字符串。(?studID=xxxxx),因此servlet将知道studID。

认为应该在JSP中取出studID,并将studID格式化为URL的查询字符串,即html页面。(?studID=xxxxx),因此servlet将知道studID。

您可以将id作为查询字符串传递到url中。简单地说:

  <a href="myservlet?id=<%=stuid%>">My Link</a>

但是,正如我前面提到的,您可能希望使用像JSTL这样的标记库,而不是将这些脚本放在页面中。有几个优点

您可以在url中将id作为查询字符串传递。简单地说:

  <a href="myservlet?id=<%=stuid%>">My Link</a>

但是,正如我前面提到的,您可能希望使用像JSTL这样的标记库,而不是将这些脚本放在页面中。有几个优点

您可以使用
request.setAttribute(“studID”、“value”)request.getAttribute(“studID”)来获取值,您可以使用
request.setAttribute(“studID”,“value”)request.getAttribute(“studID”)在servlet中获取值

如果您向我们展示一些代码,我们将更能提供帮助。如果您向我们展示一些代码,我们将更能提供帮助。
  <a href="PlanProtocol?id=<%=i%>" >Edit</a>
   request.getParameter("i");