Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP and JMS

Status
Not open for further replies.

flowertang

Programmer
Sep 27, 2002
9
HK
I have written a MDBs program and the program has been deployed. I can run the client program through the command line in different host. In the server side, it can receive the message from the client.

But how can I run the client program throght the jsp program instead of command line? Can you help me?


//client program

import javax.jms.*;
import javax.naming.*;

public class WroxQueueSender{
public static void main (String[] args){
Queue queue = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;

try{
Context jndiContext = new InitialContext();
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup("WroxOrders");
} catch (NamingException nEx){
System.out.println(nEx.toString() + "\nDoes the queue exist?");
System.exit(1);
}

try{
queueConnection = queueConnectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage();
message.setText("Please send me the new J2EE book on my account");
message.setStringProperty("Client", "Rachel Davies");
queueSender.send(message);
System.out.println("Your book has been ordered");
} catch (JMSException jmsEx){
System.out.print("Something went wring with your book order, ");
System.out.println("please try agai9n....");
System.out.println("Exception: " + jmsEx.toString());
} finally {
if (queueConnection != null){
try {
queueConnection.close();
} catch (Exception any){}
}
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top