请教,我写了个web application,部署在tomcat6中,需要访问远程的jboss5 jms服务器,发送和收取消息,请问应该如何配置我的tomcat?谢谢
解决方案 »
- struts2+hibernte实现单、多文件上传(照片和视频)
- 这个小程序如何改成一个servlet?
- 如何让文本框的值以原有的格式输出
- 用ajax怎么实现两个selectManyListBox之间互相传值?高分哦!
- 为什么在root目录下取得的结果是正确的,但是在虚拟目录下取得的结果是错误的?
- 如何在网页中实现 163的"邮件正在发送中"的功能,如在jsp+javabean模式下开发
- jsp编译问题
- jsp实现表单下载和打印的问题,急用!!
- 我问大家这种技术是怎样实现的
- 在tomtac下怎么设置自己的主目录????
- SiteMesh在weblogic10下部署中文乱码
- 如何在web-app中访问远程的jms server
import javax.naming.*;/**
* simple hello world consumer
*/
public class HelloConsumer
{
/**
* simple consumer
*/
public HelloConsumer() {
try {
Hashtable env;
Context ctx = null; env = new Hashtable(); // Store the environment variables that tell JNDI which initial context
// to use and where to find the provider. // For use with the File System JNDI Service Provider
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:///tmp/jndi"); try {
// Create the initial context.
ctx = new InitialContext(env);
} catch (NamingException ex) {
ex.printStackTrace();
System.exit(-1);
} // creating a connection factory ConnectionFactory cf= new com.sun.messaging.ConnectionFactory();
ConnectionFactory cf = null;
try {
// Lookup my connection factory from the admin object store.
// The name used here here must match the lookup name
// used when the admin object was stored.
System.out.println("Looking up Connection Factory object with lookup name: HelloConnectionFactory");
cf = (javax.jms.ConnectionFactory) ctx.lookup("HelloConnectionFactory");
System.out.println("Connection Factory object found.");
} catch (NamingException ne) {
System.err.println("Failed to lookup Connection Factory object.");
ne.printStackTrace();
System.exit(-1);
}
// create a connection
Connection connection = cf.createConnection();
// create a session
Session session = connection.createSession(
false /* not transacted */, Session.AUTO_ACKNOWLEDGE); // create destination HelloWorld
Destination destination = session.createQueue("HelloWorld"); Queue queue = null;
try {
// Lookup my queue from the admin object store.
// The name I search for here must match the lookup name used when
// the admin object was stored.
System.out.println("Looking up Queue object with lookup name: HelloQueue");
queue = (javax.jms.Queue)ctx.lookup("HelloQueue");
System.out.println("Queue object found.");
} catch (NamingException ne) {
System.err.println("Failed to lookup Queue object.");
ne.printStackTrace();
System.exit(-1);
} // create a consumer
MessageConsumer consumer = session.createConsumer(destination); // now that everything is ready to go, start the connection
connection.start(); // receive our message
TextMessage m = (TextMessage)consumer.receive(); System.out.println(m.getText()); // close everything
consumer.close();
session.close();
connection.close();
} catch (JMSException ex) {
System.out.println("Error running program");
ex.printStackTrace();
}
}
/**
* main method
*/
public static void main(String args[]) {
new HelloConsumer();
}
}