解决方案 »

  1.   

    跟J2EE一样的服务器,你android这一方面只要用json或者gson直接拿数据,后台的话用tomcat接受请求操作数据
      

  2.   

    这个很简单,我以前就弄过,不过数据量不大,用mysql做服务器的数据库
      

  3.   

    功能不复杂的话直接servlet+tomcat+MySql就行
      

  4.   

    我是服务器端(包括外网发布)和客户端一条龙开发到底的,就贴一点服务器端的代码(servlet+spring+mybatis+mysql):
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.Method;
    import java.util.HashMap;
    import java.util.Map;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.web.bind.annotation.RequestMapping;
    import com.taocaiku.gaea.common.web.annotation.AndroidDontLogin;
    import com.taocaiku.pages.util.ToolUtil;/**
     * 安卓接口的servlet
     * @author TCK-001
     * @version 1.0
     */
    @SuppressWarnings({ "rawtypes", "unchecked", "serial" })
    public class ControlServlet extends HttpServlet {

    /**
     * 初始化servlet
     * */
    @Override
    public void init() throws ServletException {
    String classPath = ToolUtil.getClasspath();
    String packArr[] = new String[] { "com.taocaiku.pages.web.controller.android" };
    for (int i = 0; i < packArr.length; i++) {
    File folder = new File(classPath + getPackagePath(packArr[i]));
    File[] files = folder.listFiles();
    for (File file : files) {
    if (file.isFile()) {
    String fileName = file.getName();
    if (fileName.indexOf(".") != -1 && ".class".equals(fileName.substring(fileName.lastIndexOf(".")))) {
    String clazz = packArr[i] + "." + fileName.substring(0, fileName.lastIndexOf("."));
    Class class1 = null;try {class1 = Class.forName(clazz);} catch (Exception e) {}
    if (null != class1 && null != class1.getAnnotation(RequestMapping.class)) {// 如果是control
    RequestMapping mapping = (RequestMapping) class1.getAnnotation(RequestMapping.class);
    String controlName = mapping.value()[0];
    if (null != BeanManager.getControl(controlName)) {// control的名称不能重复
    throw new ServletException("control名称[" + controlName + "]不能被重复声明");
    }
    ControlBean bean = new ControlBean();
    bean.setControlClass(class1);
    bean.setMethods(loadMethod(class1));
    BeanManager.setControl(controlName, bean);
    }
    }
    }
    }
    }
    }

    /**
     * 加载Control中的方法
     * @param class1
     * @return
     * @throws ServletException
     */
    private Map<String, ControlBean.InnerMethod> loadMethod(Class class1) throws ServletException {
    Map<String, ControlBean.InnerMethod> innerMethods = new HashMap<String, ControlBean.InnerMethod>();
    Method[] methods = class1.getMethods();
    for (Method method : methods) {
    if (null != method.getAnnotation(RequestMapping.class) && method.getParameterTypes().length == 0) {
    RequestMapping mapping1 = (RequestMapping) method.getAnnotation(RequestMapping.class);
    String methodKey = mapping1.value()[0];
    if (null != innerMethods.get(methodKey)) {
    throw new ServletException("方法映射名称[" + methodKey + "]不能被重复声明");
    }
    ControlBean.InnerMethod innerMethod = new ControlBean.InnerMethod();
    innerMethod.setName(method.getName());
    if (null != mapping1.method() && mapping1.method().length > 0) {
    innerMethod.setMethod(mapping1.method()[0].toString());
    }
    boolean isLogin = (null == class1.getAnnotation(AndroidDontLogin.class) && null == method.getAnnotation(AndroidDontLogin.class));
    innerMethod.setIsLogin(isLogin);
    innerMethods.put(methodKey, innerMethod);
    }
    }
    return innerMethods;
    }

    /**
     * 处理get请求
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    CenterControl.getBean().execute(request, response);
    } /**
     * 处理post请求
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException {
    this.doGet(request, response);
    }

    /**
     * 根据包名获得相对路径
     * @param packageName 包名
     * @return String
     */
    private String getPackagePath(String packageName) {
    String result = "";
    String []array = packageName.split("\\.");
    for (int i = 0; i < array.length; i++) {
    result += File.separator + array[i];
    }
    return result + File.separator;
    }}
      

  5.   

    再贴一段android客户端登录的代码:
    import java.util.Map;import org.json.JSONArray;import android.annotation.SuppressLint;
    import android.os.Bundle;
    import android.view.View;
    import android.webkit.WebView;
    import android.widget.EditText;import com.taocaiku.gaea.Config;
    import com.taocaiku.gaea.R;
    import com.taocaiku.gaea.activity.pilot.MyAct;
    import com.taocaiku.gaea.common.activity.AbstractActivity;
    import com.taocaiku.gaea.domain.Domain;
    import com.taocaiku.gaea.domain.Json;
    import com.taocaiku.gaea.domain.Member;
    import com.taocaiku.gaea.domain.context.Container;
    import com.taocaiku.gaea.domain.context.OtherUrls;
    import com.taocaiku.gaea.domain.context.TckUrls;
    import com.taocaiku.gaea.service.UpdaterService;
    import com.taocaiku.gaea.util.BrowserUtil;/**
     * 
     * 登录界面
     * 
     * @author TCK-001
     * @version 1.0
     */
    @SuppressLint({ "HandlerLeak", "SetJavaScriptEnabled" })
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public class LoginAct extends AbstractActivity { /** 视图组件 */
    private EditText txtName, txtPwd; /** 视图组件 */
    private WebView webview; /**
     * 垃圾回收
     * */
    @Override
    public void clearData() {
    super.clearObjectData();
    txtName = null;
    txtPwd = null;
    webview = null;
    } /**
     * 界面初始化
     * 
     * @param bundle
     * */
    @Override
    protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.outer_login);
    setTopTitle(true, getString(R.string.login), null, true);
    txtName = findView(R.id.txtName);
    txtPwd = findView(R.id.txtPwd);
    setUserInput();
    initBrowser();
    viewUtil.hideKeyboard(this);
    } /**
     * 初始化内嵌浏览器
     * */
    private void initBrowser() {
    webview = findView(R.id.wbvBrowser);
    Map<String, Object> gressMsg = toolUtil.createMap(new String[] {
    OtherUrls.QQ_LOGIN_URL, OtherUrls.SINA_LOGIN_URL,
    Config.TCK_DOMAIN + "/check/third.htm" }, new Object[] {
    "正在加载QQ界面...", "正在加载新浪微博界面...", "正在登录淘材库服务器..." });
    BrowserUtil.get(webview, "otherLogin.showBrowserSource", gressMsg,
    false);
    webview.addJavascriptInterface(this, "otherLogin");
    } /**
     * 登录
     * 
     * @param view
     */
    public void doLogin(View view) {
    if (notNull(getText(txtName), "用户名", true, txtName)
    && notNull(getText(txtPwd), "密码", true, txtPwd)) {
    try {
    Map<String, Object> param = toolUtil.createMap(new String[] {
    "name", "pwd" }, new Object[] { getText(txtName),
    toolUtil.toUnicode(getText(txtPwd)) });
    webUtil.setRequestParam(Domain.LONG_REQUEST_TIME,
    TckUrls.LOGIN_URL, false);
    requestTck(param, GRESS_COMMIT_MSG, "callback", false, true,
    false);
    } catch (Exception e) {
    prompt(OP_ERROR_MSG);
    }
    }
    } /**
     * 登录的回调
     * */
    public void callback() {
    try {
    resultJson.addData("member", beanUtil.jsonToBean(
    resultJson.getKeyData("member"), Member.class));
    resetMemberFile(getText(txtName), getText(txtPwd));
    UpdaterService.get()
    .initMap(
    new JSONArray(resultJson.getKeyData("updaters")
    .toString()));
    toBack(null);
    } catch (Exception e) {
    prompt(OP_ERROR_MSG);
    }
    } /**
     * 去注册
     * 
     * @param view
     */
    public void toReg(View view) {
    changeAct(RegisterAct.class, null, Domain.LEFT);
    } /**
     * 去找回密码
     * 
     * @param view
     */
    public void toFind(View view) {
    changeAct(FindPwdAct.class, null, Domain.LEFT);
    } /**
     * 后退按钮
     * 
     * @param view
     * */
    @Override
    public void toBack(View view) {
    Class last = getParam("lastActivity");
    Map<String, Object> map = (null != last
    && null != getParam("lastParam") ? (Map<String, Object>) getParam("lastParam")
    : null);
    changeAct(null == last ? MyAct.class : last, map, null);
    } /**
     * 加载保存在sd卡中的用户名和密码
     * */
    private void setUserInput() {
    Member member = null;
    try {
    member = fileUtil.turnSerialize(fileUtil.getContextRoot()
    + Domain.MEMOR_FILE);
    } catch (Exception e) {
    }
    if (null != member) {
    txtName.setText(member.getName());
    txtPwd.setText(member.getPasswd());
    }
    } /**
     * qq登录
     * 
     * @param view
     */
    public void qqLogin(View view) {
    if (!Container.pingTck || !webUtil.isNet()) {
    prompt(!webUtil.isNet() ? NET_ERR_MSG : OP_ERROR_MSG);
    return;
    }
    if (Config.TCK_IP.indexOf("taocaiku") == -1) {
    prompt("测试环境下, 该功能不可用");
    return;
    }
    findView(R.id.lltContent).setVisibility(View.GONE);
    webview.loadUrl(OtherUrls.QQ_LOGIN_URL
    + "?response_type=code&client_id=" + Domain.QQ_ID
    + "&redirect_uri="
    + OtherUrls.YIMARK_URL.replace("http://", "") + "&state=TCK"
    + Domain.QQ + "," + Domain.ANDROID);
    } /**
     * 第三方登录的回调
     * 
     * @param code
     * @param type
     * @param memberJson
     * @param updatersJson
     */
    public void otherLoginCallback(String code, String type, String memberJson,
    String updatersJson) {
    try {
    Container.otherLoginType = type;
    resultJson = new Json(true).addData("member",
    beanUtil.jsonToBean(memberJson, Member.class));
    resetMemberFile(null, null);
    UpdaterService.get().initMap(new JSONArray(updatersJson));
    toBack(null);
    } catch (Exception e) {
    prompt(OP_ERROR_MSG);
    }
    } /**
     * 微博登录
     * 
     * @param view
     */
    public void wbLogin(View view) {
    if (!Container.pingTck || !webUtil.isNet()) {
    prompt(!webUtil.isNet() ? NET_ERR_MSG : OP_ERROR_MSG);
    return;
    }
    if (Config.TCK_IP.indexOf("taocaiku") == -1) {
    prompt("测试环境下, 该功能不可用");
    return;
    }
    findView(R.id.lltContent).setVisibility(View.GONE);
    webview.loadUrl(OtherUrls.SINA_LOGIN_URL + "?client_id=" + Domain.WB_ID
    + "&response_type=code&redirect_uri=" + OtherUrls.YIMARK_URL
    + "&state=TCK" + Domain.WB + "," + Domain.ANDROID);
    } /**
     * 显示webview的源代码
     * 
     * @param html
     */
    public void showBrowserSource(String html) {
    System.out.println(html);
    }}
      

  6.   

    为了省事的话直接还是按照web服务端的方式搭建吧,而且在并发方面也有很多可以见鉴的例子