The existing P2P routing algorithms generally don't take routing security into consideration. Therefore P2P overlay systems are vulnerable to a kind of attacks called misrouting attacks. This is especially serious in structured P2P overlays due to the deterministic routing algorithms. What's more, in dynamic network environments, the continuous process of node arrival and departure, churn, makes peers' routing table lose accuracy and may lead to the increase of system latency. In this paper, we propose a trust-based routing strategy in structured P2P systems to solve these problems, using quantified trust degree to select next-hops and neighbors. Not only direct trust, but also indirect trust is used for optimization. At the end of this paper, the simulation results show that this trust-based routing strategy leads to higher look-up success rate compared to the original routing algorithm, with the same magnitude of cost.