我正在做一个java项目,在这个项目中我实现了一个聊天,只有当我收到消息我无法打印网页时,所有东西都能正常工作。 在我的Servlet中,我有一个回调方法,在消息到达时调用,实际上如果您在控制台中看到它们,但是如果使用RequestDispatcher将它们发送给jsp,则无法让它们看到。从servlet java发送数据到jsp
我想知道如果有一个JSP页面监听在servlet回调方法的系统?
显然,这个系统不应该不断地调用该类我有一些荒谬的那样。
这样我就可以打印我收到的消息。
这是我的代码,我把一个评论,我应该打印最终找到在jsp页面,或通过传递参数发布或获取
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页面打印出来 –