flowertang
Programmer
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){}
}
}
}
}
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){}
}
}
}
}