如何从servlet响应客户端?

时间:2012-04-07 20:34:57

标签: android google-app-engine

我正在尝试使用谷歌应用引擎和Android应用程序进行简单的静态登录:

服务器:

public class StreetMeetSignServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)     throws  IOException 
    {
        PrintWriter out = response.getWriter();
        String userName,password;   
        userName = request.getParameter("username");
        password = request.getParameter("password");
        if(userName.equalsIgnoreCase("A") && password.equals("B"))
        {
            out.print("yes");
        }
        else
        {
            out.print("no");
        }       
    }
}

客户代码:

    response = CustomHttpClient.executeHttpPost("http://myserver.appspot.com/", postParameters);

    String res=response.toString();
    System.out.println("res is: "  + res);
    res= res.replaceAll("\\s+","");

    if(res.equals("yes"))
        error.setText("Correct Username or Password");
    else
        error.setText("Sorry!! Incorrect Username or Password");

但是在res字符串中我有我的jsp上生成的所有html代码..
那是为什么?
有一个从A到Z的教程,展示如何将Android应用程序连接到谷歌应用程序引擎servlet?

1 个答案:

答案 0 :(得分:1)

executeHttpPost方法中,您应该将完整路径传递给您的servlet,例如

    response = CustomHttpClient.executeHttpPost("http://myserver.appspot.com/path/to/servlet", postParameters);

您是否在web.xml注册了servlet?路径是什么?