2

继承人的代码
它基本上需要一条消息并将其回显。问题是它根本没有回复:(在谷歌应用程序引擎,我的应用程序页面中,我收到错误-“在此服务器上找不到请求的 URL /guestbook。”

package guestbook;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.*;
import com.google.appengine.api.xmpp.JID;
import com.google.appengine.api.xmpp.Message;
import com.google.appengine.api.xmpp.MessageBuilder;
import com.google.appengine.api.xmpp.XMPPService;
import com.google.appengine.api.xmpp.XMPPServiceFactory;






@SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {

private static final Logger LOG = 
          Logger.getLogger(GuestbookServlet.class.getName());

public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {

       // Parse incoming message
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message msg = xmpp.parseMessage(req);
    JID jid = msg.getFromJid();
    String body = msg.getBody();
    LOG.info(jid.getId() + " --> JEliza: " + body);

    // Get a response from Eliza
    String response = "echo: " + body;
    LOG.info(jid.getId() + " <-- JEliza: " + response);

    // Send out response
    msg = new MessageBuilder()
        .withRecipientJids(jid)
        .withBody(response)
        .build();
    xmpp.sendMessage(msg);

    /*Message message = xmpp.parseMessage(req);
    JID fromJid = message.getFromJid();
    String body = message.getBody();

    String respMsg = null;

    if (body.equals("/list")) {
        respMsg = "Hi";
      } else if (body.equals("/help")) {
        respMsg = "Welcome to the Guestbook Chatbot!\nThe following commands are supported: \n /list \n /help";
      } else {
        respMsg = "Command '" + body + "' not supported! \nEnter '/help' for list of commands.";
      }

    JID tojid = new JID(fromJid.getId());

    Message msg = new MessageBuilder().withRecipientJids(tojid).withBody(respMsg).build();

    boolean messageSent = false;
    xmpp = XMPPServiceFactory.getXMPPService();
    if (xmpp.getPresence(tojid).isAvailable()) {
      SendResponse status = xmpp.sendMessage(msg);
      messageSent = (status.getStatusMap().get(tojid) == SendResponse.Status.SUCCESS);
    }*/

  }



}
4

2 回答 2

1

根据您提供的详细信息,我认为问题应该出在 web.xml 文件上

<servlet><servlet-name>GuestbookServlet</servlet-name><servlet-class>your.package.structure.GuestbookServlet</servlet-class></servlet><servlet-mapping><servlet-name>GuestbookServlet</servlet-name><url-pattern>/_ah/xmpp/message/chat/</url-pattern></servlet-mapping>

尝试将其添加到 web.xml 中相应地更改 your.package.structure.GuestbookServlet 例如我的将是 com.appengine.capp

于 2012-07-08T14:21:54.483 回答
0

JDK 设置必须从 1.7 更改为 1.6。在窗口-> 首选项-> java -> 编译器下

于 2012-07-09T08:38:48.070 回答