Instead of doing a lookup:
DataSource ds = (javax.sql.DataSource) ctx.lookup("java:jboss/datasources/Test");
use injection:
@Resource (mappedName="java:jboss/datasources/Test")
private DataSource ds;
That'll setup the appropriate dependencies between the servlet and the datasource.