Problema com jsp e html

Estou precisando de um botao para cada linha de uma tabela. Fiz com um for para ver se era do jeito que eu queria e vejo que é realmente, porém, desse jeito os botões ficam iguais em termo de funcionalidades.
Existe alguma possibilidade de fazer com que dentro de um for, os botoes tenham funcionalidades diferente?
Se não, como que poderia ser?
Alguém pode me ajudar?

<%@ page import="Produtos.*,java.util.*" language="java"
	contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
	<!-- form action="carrinho.jsp" method="post">
		Cursos:
		<table border="1" cellpadding="10">
			<tr>
				<td><b>Nome</b>
				<td><b>Descrição</b>
				<td><b>Preço</b>
			</tr>
		
		</table>
		<input type="submit" value="Carrinho">
		
	</form-->

<h1>Cursos</h1>
		<form action="carrinho.jsp" method="POST">
		<table border="1" cellpadding="10">
				
			
				<tr>
                       <td>Código
                       <td>Nome
                       <td>Preço
                </tr>
                
                <%
                GerenteDeProduto gerenciador = new GerenteDeProduto();
                List<Produto> produtos = gerenciador.carregarListaProdutos();
                for (Produto p: produtos) {%>
        		<tr>
        			<td><%=p.getCodigo()%></td>
        			<td><%=p.getNome()%></td>
        			<td><%="R$ "+p.getPreco()%></td>
        			<td><input type="submit" value="Comprar" action="carrinho.jsp"/>
        		</tr>
        		<%
        			}
        		
        		%>              
               
		</table>
			
		</form>


</body>
</html>

Algo mais ou menos assim?

 for (Produto p: produtos) {%&gt;  
                &lt;tr&gt;  
                    &lt;td&gt;&lt;%=p.getCodigo()%&gt;&lt;/td&gt;  
                    &lt;td&gt;&lt;%=p.getNome()%&gt;&lt;/td&gt;  
                    &lt;td&gt;&lt;%="R$ "+p.getPreco()%&gt;&lt;/td&gt;  
                    &lt;td&gt;&lt;input type="submit" value="Comprar" action="carrinho.jsp?idProduto="+p.getCodigo()/&gt;  
                &lt;/tr&gt; 

Acredito que realmente seja dessa forma,
Porém, como que em carrinho.jsp eu pego o valor desse votão?

tentei isso mas sem sucesso.

<%String valor = request.getParameter("Comprar");
               out.println(valor);

alguém pode me ajudar?

se voce colocar a action action="carrinho.jsp?idProduto="p.getCodigo()

voce vai pegar na pagina carrinho.jsp com

   request.getParameter("idProduto");

Continua dando erro:
Imprime Null

	<form action="carrinho.jsp" method="post">
		<table border="1" cellpadding="10">
				
			
				<tr>
                       <td>Código
                       <td>Nome
                       <td>Preço
                </tr>
                
                <%
                GerenteDeProduto gerenciador = new GerenteDeProduto();
                List<Produto> produtos = gerenciador.carregarListaProdutos();
                for (Produto p: produtos) {%>
        		<tr>
        			<td><%=p.getCodigo()%></td>
        			<td><%=p.getNome()%></td>
        			<td><%="R$ "+p.getPreco()%></td>
        			<td><input type="submit" value="Comprar" action="carrinho.jsp?idProduto="+p.getCodigo()/> 
        		</tr>
        		<%
        			}
        		
        		%>              
               
		</table>
			
		</form>
<table border="1" cellpadding="10">
               <tr>
                       <td>Código
                       <td>Nome
                       <td>Preço
               </tr>
               
           
               <%String valor = request.getParameter("idProduto");  ;
               out.println(valor);
               %>
               
                           
              
       </table>

usa um input text do tipo hiden e passa o IdProduto e recupera pelo getParameter