【发布时间】:2013-05-27 05:40:57
【问题描述】:
我正在用 java 做一个项目,其中我实现了一个聊天,只有当我收到无法打印网页的消息时,一切才能完美运行。 在我的 Servlet 中,我有一个回调方法,当消息到达时会调用它,事实上,如果您在控制台中看到它们,但是如果您使用 RequestDispatcher 将它们发送到 jsp,则无法让它们看到。
想知道有没有jsp页面监听servlet中回调方法的系统?
显然,这个系统不应该不断地调用类我有这样的荒谬。
以便我可以打印收到的消息。
这是我的代码,我在应该打印的地方添加了注释,最终在 jsp 页面中找到,或者通过传递参数 post 或 get 进行重定向
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String strJid = (String) request.getParameter("jid");
String strMessage = (String) request.getParameter("textMessage");
Connection connection = (Connection)getServletContext().getAttribute("classConnection");
ChatManager chatManager = connection.getChatManager();
Chat newChat = chatManager.createChat(strJid, new MessageListener(){
@Override
public void processMessage(Chat chat, Message message){
//from here I have to print the message.getBody () in jsp page,
//how can I do? I'm happy also reload the page and pass as a parameter to get or post
}
});
try{
newChat.sendMessage(strMessage);
}
catch(XMPPException e){
System.out.println("Errore invio messaggio");
}
}
【问题讨论】:
-
无法清楚地理解您在寻找什么,请用一些代码更新您的问题,并且可能会逐步解释您正在尝试做什么以及您遇到的问题。谢谢
-
我的观点是,当servlet通过回调方法接收消息时,我无法在jsp页面中打印它们