Web ontologies, which usually appear as RDF graphs, are used to represent knowledge in web. In recent years, with the wide application of Semantic Web, large numbers of such web ontologies have appeared on the Internet, especially, in some virtual knowledge communities. These web ontologies are usually distributed in different sites and provide an amount of knowledge to query. But, it has become a pressing issue that, given a semantic query, how to efficiently gather the related knowledge from these web ontologies located in different sites to process it. To address this issue, in this paper, we propose a P2P-based approach to publish RDF triples in sharable web ontologies and freely sharing them in an open distributed environment. Given a query of SPARQL (Simple Protocol and RDF Query Language), this approach can automatically gather published RDF triples related to the query to process the query. As a knowledge sharing approach, our approach can directly share RDF triples coming from different web ontologies on different nodes. It overcomes limitations of those approaches which focus on how to locate related ontologies for a query. We also conducted three experiments to evaluate the effectiveness and the efficiency of our approach. The experimental results demonstrated that it is effective and efficient.